Does defold support only three shapes for collision? (SOLVED)

does defold support only three shapes for collision?

Actually four. You can also assign a tilemap as shape:

With physics debug enabled:

3 Likes

Actually five. You can create your own convex hull shape with a .convexshape file, something like;

shape_type: TYPE_HULL
data: -10 data: -10 data: 0
data: 10 data: -10 data: 0
data: 0 data: 10 data: 0

This should create a triangle shape (I think, haven’t tested it).

7 Likes

Oh, nice, I didn’t know about that!

2 Likes

thank you!!!(because we need at least 20 characters to reply) :laughing:

1 Like

Wow, that was news to me. enlighted…

2 Likes

Could you check this again / upload a sample?

I tried to get it work work but got this error

Could not open the editor: collisionobject node could not be loaded: Not implemented: TYPE_HULL

I created a test.convexshape file, edited it as text at first but we seem to have a very basic editor for it as well:

Then I created my go-file, added a collisionobject component and set the “Collision Shape” to the test.convexshape file:

(I don’t think we render it correctly in the collection editor though, but it should show up in the engine.)

4 Likes

Hello @sven

I am trying to port my game to defold. Need some collider power! Endup with this topic.
I couldnt make it work.

It shows the points on editor, but crashes on build. Also gives a warning on editor;

`Assertion failed: 3 <= count && count <= 16, file …\src\box2d\Box2D\Collision\Shapes\b2PolygonShape.cpp, line 122

Than i reduce to points to 5 (5*3=15)

Assertion failed: area > 1.192092896e-07F, file …\src\box2d\Box2D\Collision\Shapes\b2PolygonShape.cpp, line 115

Is there any other way to add collider from image alpha. Or its only the primitive colliders for now.

Best Regards,

If you use tilesources you can get shapes from alpha. Check out http://www.defold.com/manuals/physics/#anchor-tcs

Note too that the polygon you specify has to be convex. I’m not sure but the area message might indicate that your shape is not.

Hello @sicher

I used that method. But i didn’t satisfied with the result. Maybe it works with little tiles, didn’t try it.

I think i will stick with default colliders for now.

Best Regards,

1 Like

Since you have “valleys” in the ground shape you can’t get a convex shape to fit well. You will have to split it in pieces (tiles) that are convex, or work with multiple simple shapes as you currently do.

2 Likes

is it still possible to create convexshape file in editor 2?

Try using this https://github.com/rgrams/defold_polygon_editor

thank you

hm, an error happens while using generated file

Assertion failed: (3 <= count && count <= 16), function Set, file …/src/box2d/Box2D/Collision/Shapes/b2PolygonShape.cpp, line 122.

image file is the same as was used for shape…

ping @ross.grams

1 Like

Ooh, sorry about that. I fiddled around a bit and it looks like Box2D won’t take a polygon with more than 16 vertices. If you simplify your shape it should work, let me know if it doesn’t.

2 Likes

thank you for reply :slight_smile: the same that I thought by the error but was not sure

3 Likes

I’m currently looking for a solution for this.

I want to have a hex-shaped collision. Right now I’m thinking of writing my own .convexshape file or using tile collisions. I’m not sure which one is the better option.

The tile collision option would be to use multiple small tiles, around 16x16. The collisions would not involve physics. They’re mainly for triggers.