Page 1 of 1

Is there a Chipmunk library for movement using forces/impuls

Posted: Wed Jan 20, 2010 5:02 pm
by micksabox
Hello,

I am developing a top-down 2D iPhone game and I need some sort of library or function for Chipmunk or cocos2d iphone that handles movement in 2-dimensional space using forces or impulse.

Note: There is no gravitity force since it is a top down game.
Note: Again, this will be in Objective-C.

So the function would be something like this:

-(void)moveSprite:(AtlasSprite *)sprite ToPoint:(CGPoint) point{

//Function or library that applies the proper physics and/or impulses to AtlasSprite sprite to get to CGPoint point

}
I just want to know if such a library or function exists. Has anybody implemented this or heard/knows of such a library/function? The problem I have is that it is a little hard to understand forces and vectors and impulses, as testing with them has produced inconsistent results. I WILL have to create the above function manually from scratch either way, therefore I was wondering if I could save myself a little time.

Thanks a lot

Re: Is there a Chipmunk library for movement using forces/impuls

Posted: Wed Jan 20, 2010 5:26 pm
by viblo
cpBodySlew?

Re: Is there a Chipmunk library for movement using forces/impuls

Posted: Wed Jan 20, 2010 5:47 pm
by micksabox
viblo wrote:cpBodySlew?
Yes, that works! Thanks a lot. One caveat: The sprite does not stop upon reaching its destination point. Any suggestions? (Sorry, I'm still kind of new to chimpunk and game physics in general).

Thanks a TON.

Re: Is there a Chipmunk library for movement using forces/impuls

Posted: Thu Jan 21, 2010 11:02 pm
by mobilebros
Of course I will not pass up the opportunity to shamefully promote the chipmunk-spacemanager specifically written to handle chipmunk with cocos2d-iphone, or even obj-c in general. Its here:

http://code.google.com/p/chipmunk-spacemanager/

If you use cpSprite/cpAtlasSprite/cpShapeNode and then set it's integrationDt to match whatever dt you use in your game loop, then it will indeed do a cpBodySlew correctly based on how you set the position....

You say you used cpBodySlew but it keeps moving after the destination? Its because cpBodySlew sets the velocity, if its any distance traveled at all velocity will not be zero; so the only way for it to actually "stop" would be for you to set the velocity to cpvzero.