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), new Vector3f(0, 0, 0)); } } public void physicsTick(PhysicsSpace space, float tpf) {}
Remember to register the
TickListener
(this class) to the physics space.public void simpleInitApp() { … bulletAppState...