I have this method that creates a sphere “soccer ball”:
` public void makeBall() {
/** Create a cannon ball geometry and attach to scene graph. */
Material dirt = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
TextureKey key2 = new TextureKey("Textures/textureball.png");
key2.setGenerateMips(true);
Texture tex2 = assetManager.loadTexture(key2);
dirt.setTexture("ColorMap", tex2);
sphere = new Sphere(32, 32, 0.4f, true, false);
Geometry ball_geo = new Geometry("ball", sphere);
ball_geo.setMaterial(dirt);
ball_geo.setShadowMode(ShadowMode.CastAndReceive);
rootNode.attachChild(ball_geo);
/** Position the cannon ball */
ball_geo.setLocalTranslation(cam.getLocation());
/** Make the ball physcial with a mass > 0.0f */
ball_phy = new RigidBodyControl(0.5f);
/** Add physical ball to physics space. */
ball_geo.addControl(ball_phy);
ball_phy.setDamping(0.1f, 0.1f);
/** Accelerate the physcial ball to shoot it. */
ball_phy.setRestitution(1.0f);
ball_phy.setMass(1.0f);
}
And I have a CharacterControl player; which moves around using WASD.
I want it to happen so when the player runs up to the football and hits the football, the ball moves like it has been kicked. I can’t seem to get it to work. Thanks a lot for any help.