+1 vote

Hi,

I'm currently working on terrain generation, using a simple diamond square algorithm , that generates an Image (put_pixel) which is then loaded into TextureImage etc. This works fine, albeit a bit slow. But then there is collision detection.

Is it possible to implement custom Shape2D which the physicsserver can handle?

From looking at the Godot source code, it does not seem possible :-/

In general it would be nice to have a Node2D derivative, that has a Texture property, and a TextureShape2D that uses same said texture to do bitmap collision detection, calculate collision normal etc. (i.e. as done in http://gamedevelopment.tutsplus.com/tutorials/coding-destructible-pixel-terrain--gamedev-45)

Of course it could currently be faked by using a rather large CollisionPolygon2D (screen.width + 2 points) but I'm not sure the engine would handle that very well or at all, and it would necessary to update the polygon every time part of the "bitmap" is destroyed/changed :-)

So what are your thoughts? any chance that we will se "bitmap" collision support in Godot?

in Engine by (17 points)
edited by

1 Answer

+1 vote

Use Polygon2D, That allows you to pretty much draw the shape you want. CollisionPolygon2D for collision shape.

by (223 points)

thx :-)

Works nicely with Polygon2D, but I can't figure out how to use CollisionPolygon2D runtime (Which is designed to be an Editor helper, that partitions the polygon into shapes and updates its parent (CollisionObject2D)) and not as such usable via get_node etc.

I've tried instantiating it runtime, but it fails to trigger updateparent() (protected method) which then calls updateshapesfromchildren() on the parent (which is not public available, https://github.com/godotengine/godot/blob/master/scene/2d/collision_object_2d.h)

I would hate to decompose the polygon my self :-/ Any suggestions?

UPDATE! I'm using the ConcavePolygonShape2D in the meanwhile, but I suspect better performance from several convex shapes (hence the decomposition need)

You don't use collisionpolygon runtime for that, you access the collisionbody and use add_shape(polygon)

example:


var polygon = polygon2d.new() then set the shape of polygon Rigidbody2D.add_shape(polygon)

edit: since your description implies you'd be adding/and removing shapes, it might also be in your best interest to keep track of the shapes' IDXs making it easier to add and remove them. I don't have Godot up as I write this to get the commands needed, but they should be in Godot's help still. I just know to remove, scale or check which shape got hit on a physicsbody, you need the IDX.

Hi,

Yes that is what ended up doing, using ConcavePolygonShape2d. I just do a clearshapes() followed by addshape() works fine :-)

I would be nice thou to have access to the decomposition feature of CollisionPolygon2d, thus avoiding concave polygons all together and their inherit performance hit.

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.