Time for action – react to collisions

Let's add a dynamic object to the scene to see what happens when it falls onto the platform. You already know how to create a nicely textured sphere and turn it into a physical ball.

Open PhysicsKinematic.java again and add the following method:

private RigidBodyControl ballPhy; private static final String BALL = "Ball"; public void dropBall() { Sphere ballMesh = new Sphere(32, 32, .75f, true, false); ballMesh.setTextureMode(TextureMode.Projected); TangentBinormalGenerator.generate(ballMesh); Geometry ballGeo = new Geometry(BALL, ballMesh); ballGeo.setMaterial(stoneMat); rootNode.attachChild(ballGeo); /** Create physical ball and add to physics space. */ ballPhy = new RigidBodyControl(5f); ballGeo.addControl(ballPhy); ...

Get jMonkeyEngine 3.0 Beginner's Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.