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.

  1. Open PhysicsKinematic.java again and make it implement the PhysicsTickListener interface.
    public class PhysicsKinematic extends SimpleApplication
            implements PhysicsCollisionListener, PhysicsTickListener {…}
  2. The interface requires you to implement two methods: prePhysicsTick() and physicsTick(). Use the prePhysicsTick() 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.