assigning physics shape to a dynamic object

Hello,

I am stuck with a problem and unfortunately I was not able to find any similar problems or solutions

what I’m trying to do is assigning a custom shape to the feet of the character so when the character collides with other static objects (like trees etc), the output will be more realistic

example:

attached static.jpg -> as the character is a rectangular shape, the head of the skeleton stops when intersect with the tree

dynamic.jpg -> as I have assigned a shape to the feet of the character, it can stand at a more realistic position

so back to the problem:

I’m creating a dynamic character object and assigning it a custom shape

 local charFeet= { -16,16, 16,16, -16,32, 16,32 }
 physics.addBody( char, “dynamic”, {friction=0.5, bounce=0.3, shape=charFeet} )
 

This works fine on the simulator but when I try the application of android device, the character is not printed on the screen (I’m also calling the character toFront so its not related with that)

if i skip the assignment of shape, it works fine.with the following code

 physics.addBody( char, “dynamic”, {friction=0.5, bounce=0.3} )

when I use static instead of dynamic, the character is printed on the screen of the device, everything is working smoothly except as the character is static it can pass through other static objects like a ghost

so I would like to learn

-why does assigning a shape to a dynamic object creates the problem? what is the logic?

-is there a way to tell the physics that two static objects should not intersect with each other

thanks

Hi @cemadil,

It appears that you’re putting the coordinates of your custom shape in the wrong order. When setting the vertices (pairs) for each point of the custom shape, you must declare them in clockwise order. Also, there can not be any concave angles… it appears that you’re just trying to draw a rectangle lower down on the overall body, so you don’t have that issue, but remember it for the future.

And you ask:

-is there a way to tell the physics that two static objects should not intersect with each other

If you’re asking whether two static objects can sense collision against each other, the answer is no: at least one body in a collision must be a dynamic body.

Hope this helps,

Brent

Thank you very much, works like a charm. I can’t believe I did not notice that :slight_smile:

Hi @cemadil,

It appears that you’re putting the coordinates of your custom shape in the wrong order. When setting the vertices (pairs) for each point of the custom shape, you must declare them in clockwise order. Also, there can not be any concave angles… it appears that you’re just trying to draw a rectangle lower down on the overall body, so you don’t have that issue, but remember it for the future.

And you ask:

-is there a way to tell the physics that two static objects should not intersect with each other

If you’re asking whether two static objects can sense collision against each other, the answer is no: at least one body in a collision must be a dynamic body.

Hope this helps,

Brent

Thank you very much, works like a charm. I can’t believe I did not notice that :slight_smile: