Time for action – flying cannon balls

Let's keep the default navigational inputs in our PhysicsFallingBricks.java, and simply add a shoot action. Every time the user clicks, you want to shoot a cannon ball from the camera position forward.

  1. Write a shootCannonBall() method that creates a new physical geometry ballGeo from our ballMesh shape and stoneMat material. The setLinearVelocity() line defines the initial speed and direction of the object. In this case, we accelerate the cannon ball forward.
     public void shootCannonBall() { Geometry ballGeo = new Geometry("cannon ball", ballMesh); ballGeo.setMaterial(stoneMat); ballGeo.setLocalTranslation(cam.getLocation()); rootNode.attachChild(ballGeo); ballPhy = new RigidBodyControl(5f); ballPhy.setCcdSweptSphereRadius(.1f); ...

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.