Dynamic shapes for single body / sleeping shapes

Official forum for the Chipmunk2D Physics Library.
Post Reply
szaki
Posts: 2
Joined: Wed Jan 30, 2013 11:18 am
Contact:

Dynamic shapes for single body / sleeping shapes

Post by szaki »

Hey slembcke,

I have started to develop a game with Objective-Chipmunk physics and I would have a design/engine related question. I'm kinda new to Chipmunk and even physics engines but I have read through most part of the available documentation and have already have been able to write my first demo app.
Before I jump into coding the game, I wanted to ask you about something related to shapes.

Let's say I have an object that can move around the space and it has several states like moving, attacking, etc. Each state has its own (animated) image which have different collision shapes. So basically the object would have a single Chipmunk body and multiple Chipmunk shapes but at a single time, only one shape should be 'active'.

And there comes my question: what is the best way to implement that? I saw that bodies have a sleep property but shapes do not have such. Should I just always remove the current shape and add the new one when the object changes its state? Could there be performance issues if I do this too often?
I was also thinking about what if the object has different shapes per animation frame which would increase the number of shape changes a lot more. What about that?
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Dynamic shapes for single body / sleeping shapes

Post by slembcke »

You can change the size/shape of a body at runtime, but you shouldn't. Mostly for the same reasons in this thread:
http://chipmunk-physics.net/forum/viewt ... 32&p=11184

You need to be able to provide information to the physics on how an object moved, not just instantaneous changes to it's shape. This is why almost all games, even the AAA ones, use a single collision shape for the player that never changes. Most of the time it's a pill shape for the player's collision with the environment. Things like projectile collisions are usually done with separate (non-physics) collision data that more closely matches the rendered shape.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
szaki
Posts: 2
Joined: Wed Jan 30, 2013 11:18 am
Contact:

Re: Dynamic shapes for single body / sleeping shapes

Post by szaki »

Thanks for the quick response!

I have read the other topic and I completely understand what you say.
Would this also be a problem if the object is only a sensor? Meaning I would only need to know whether it touched the player in any way but the event would make no physical reaction. It could just mean loose hp, remove the object or something like that. So basically the only thing I would need to know if they touched. Considering this, do you still suggest to have static collsion shapes? If not, I would return to my original question so that adding/removing shapes to the space is the best option to change between the predefined shapes and whether this would cause any performance issues?

Thanks,
Szaki
Post Reply

Who is online

Users browsing this forum: No registered users and 25 guests