0

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!

4

2 に答える 2

0

cpBodySlew() を使用していないときは、オブジェクトの速度を更新していません。真っ直ぐ落ちるのはそのためです。

それを行うためのより良い方法は、公式のデモがマウス制御を実装するために行うように、力でクランプされたピボット ジョイントを使用することです。http://code.google.com/p/chipmunk-physics/source/browse/trunk/Demo/ChipmunkDemo.c#296

于 2010-05-02T17:05:12.163 に答える
0

本体をスペースから一時的に取り除きます。

オブジェクトを離したときに慣性を持たせたい場合は、話は別です。最もクリーンな方法は、ボールと指の制御下で動く一時的なセンサー本体の間にかなり硬いスプリングを取り付けることです。指を離すと、ボールをドラッグしていたときのキネマティクスが保持されます。この場合、スペースからボールを​​取り除かないでください。

于 2010-05-01T13:13:30.177 に答える