Time for action – timing forces correctly
We want the platform to go down after the ball rolls off, but currently, the ball doesn't have enough momentum to roll off by itself. Let's give it a little push.
- Open
PhysicsKinematic.java
again and make it implement thePhysicsTickListener
interface.public class PhysicsKinematic extends SimpleApplication implements PhysicsCollisionListener, PhysicsTickListener {…}
- The interface requires you to implement two methods:
prePhysicsTick()
andphysicsTick()
. Use theprePhysicsTick()
method to apply a pushing force on the ball when the platform reaches the top floor.public void prePhysicsTick(PhysicsSpace space, float tpf) { if (isBallOnPlatform && isPlatformOnTop) { ballPhy.applyImpulse(new Vector3f(2, 0, 0), ...
Get jMonkeyEngine 3.0 Beginner's Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.