0
votes

I have a simple project built with Cocos2D and Chipmunk. So far it's just a Ball (body, shape & sprite) bouncing on the Ground (a static line segment at the bottom of the screen).

I implemented the ccTouchesBegan/Moved/Ended methods to drag the ball around. I've tried both:

cpBodySlew(ballBody, touchPoint, 1.0/60.0f);

and

ballBody->p = cgPointMake(touchPoint.x,touchPoint.y);

and while the Ball does follow my dragging, it's still being affected by gravity and it tries to go down (which causes velocity problems and others).

Does anyone know of the preferred way to Drag an active Body while the physics simulation is going on? Do I need somehow to stop the simulation and turn it back on afterwards?

Thanks!

2

2 Answers

0
votes

Temporarily remove the body from the space.

If you want the object to have inertia when you release it, that's a different story. The cleanest way is to attach a fairly stiff spring between the ball and a temporary sensor body that moves under the control of your finger. When you let go with your finger, the ball will retain whatever kinematics it had while you were dragging it. Be sure not to remove the ball from the space in this case.

0
votes

You aren't updating the velocity of the object when you aren't using cpBodySlew(). That is why it falls straight down.

A better way to do it is to use a force clamped pivot joint like the official demos do to implement mouse control. http://code.google.com/p/chipmunk-physics/source/browse/trunk/Demo/ChipmunkDemo.c#296