O'Reilly logo

jMonkeyEngine 3.0 Beginner's Guide by Ruth Kusterer

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required