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 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.