0 votes

I'm making a game where the user can make and import a map, and then play it. The game is like a platformer mixed with a sandbox, and to make the map they get the background, the music, and a .png file that would be used to mark the collision.I don't think using tilesets would help. Is there a script using CollisionPolygon2D that makes a collider in the same shape as the sprite? This is my first time using Godot, so I'm not that skilled, but I'm slowly learning! :D

in Engine by (16 points)
edited by

2 Answers

0 votes

Hello hissapower,

I'm new at this myself but I think what you may be looking for is the "CollisionPolygon2D" node for your sprite.

If you add this as a child to the sprite node that you've imported into the game and draw the collision shape around your sprite with CollisionPolygon2D, you should get something like what you're looking for.

As for using the .png file as the collision shape itself via code, that's quite a bit more technical (as far as I currently know); but someone else here may be able to help you with that :)

Here's a guide I found on Godot Docs that has more information.

http://docs.godotengine.org/en/stable/learning/features/2d/using_tilemaps.html

Hope that helps and good luck!

by (70 points)

Thanks Tinkleberg, but that wasn't what I needed. Although I'm really grateful that you tried to help, tilesets won't combine with my game.But thanks, anyway! I tried to explain it with more details, if it helps! :)

0 votes

This is not something simple to do, you need to access the Image data, create an optimal polygon from that, then triangulate the polygon into convex shapes and add it to a CollisionObject2D (because concave shapes can be problematic).

I guess that you should be able to find generic algorithms for all the steps on different places and adapt it to use in Godot.

by (7,894 points)

Do you know where could I learn to do all that? Like a video, or a page in Godot Docs?

Nope :/

Is something too specific, you need to search for image processing, basic graphic editors can do that so there should be a known algorithm or technique (maybe edge detection?).

The polygon optimization, because you don't want many points, is more math thing, triangulation too.


There is another option, if your game is not too complex it may work but you will have to do your own physics.

Check this https://twitter.com/bogdan_kustan/status/832993691325386752

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.