1
votes

So I am working on a game, essentially, its a top down view of a ball. When I click the ball, I basically want to launch it in a given direction. It would be instantaneous force (think hitting a pool ball with the cue). I am trying to use applyImpulse to do this.

So far I've got:

 cpBodyApplyImpulse(sprite.body, 
                    cpBodyLocal2World(sprite.body, cpv(0.0, 1.0)), 
                    cpBodyLocal2World(sprite.body, cpv(0.0, 0.0))
 );

As I understand it, the 2 vectors that this function takes in is "world-coords" so what I am doing is visualizing everything in body-relative coordinates and then converting them to world coords.

From my above code, I would think that the ball would launch straight up with no rotation because it is a vector in the positive-y direction applied at the center of gravity. However, the ball ends up going to the right, spinning uncontrollably. Any ideas why this is happening, and how I achieve what I am trying to do?

1

1 Answers

1
votes

cpBodyApplyImpulse takes imputs in body coordinates, not world.

Try just this :

cpBodyApplyImpulse(sprite.body, 
                    cpv(0.0, 1.0), 
                    cpv(0.0, 0.0));