Character AABBs for Character States

Official forum for the Chipmunk2D Physics Library.
Post Reply
viperld
Posts: 2
Joined: Fri Jan 18, 2013 11:31 am
Contact:

Character AABBs for Character States

Post by viperld »

Hello and thank you for reading my question. :D

I am currently using the Chipmunk C-API to create a small system where there is a character with several states (stand, jump, run...). Each of these states has an animation and a cpBody with possibly several cpShapes attached. The idea is that the state will change given input ( touch nothing and they stand, touch the space key and they jump), and the appropriate animation and body/shapes for the character will change to match the new state.

I would like to know, what is the best way to "enable" and "disable" the bodies/shapes when I need to switch to or from them being the desired "active" body/shapes?

:?: Would it make sense to create a "disabled" type to set these things to? That way, I could have no collision handler that uses this "disabled" type so those shapes would never generate collisions correct? Would this still have an impact on the collision filtering stage? I'm worried about the amount of bodies/shapes that aren't being used creating unnecessary work for the system.

Are there any better or more efficient ways?
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Character AABBs for Character States

Post by slembcke »

Honestly, I'd say the best solution is not to fit your player's shape too tightly. Just use a simple shape like a beveled line segment, box, or maybe an octagon. Games that change the player's collision shape as they move tend to be really frustrating as it usually makes your player get caught on things as the states change. I cannot think of a single commercial game that does that.

If you really want to change the shape, probably the simplest way is simply to add and remove the different shapes as necessary. A shape that is not added to a space costs no CPU time. Another option is to set the layer bitmask to 0. That will mean that it's never in the same layer as anything else, and can never collide. When you want to enable it again, change the layers back to the previous value.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
viperld
Posts: 2
Joined: Fri Jan 18, 2013 11:31 am
Contact:

Re: Character AABBs for Character States

Post by viperld »

Thank you very much for your response (it was fast too lol).

I agree that it would be best to simplify the shapes and use just the one for the character. The problem though is that the animations get to be rather varied and accuracy is a key concern for everyone involved (for example, sometimes it's tall and boxy, other times it's short and wide).

I believe that I will take your advice and maintain the necessary shape info to add/remove it from the body when needed (to minimize CPU work).
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 21 guests