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.
Write a
shootCannonBall()
method that creates a new physical geometryballGeo
from ourballMesh
shape andstoneMat
material. ThesetLinearVelocity()
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); ballPhy.setCcdMotionThreshold(0.001f); ballPhy.setLinearVelocity(cam.getDirection().mult(50)); ballGeo.addControl(ballPhy); bulletAppState.getPhysicsSpace().add(ballPhy); }
Create an
actionListener...