How to make player kick ball

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");
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);
/** Position the cannon ball  */
/** Make the ball physcial with a mass > 0.0f */
ball_phy = new RigidBodyControl(0.5f);

/** Add physical ball to physics space. */
ball_phy.setDamping(0.1f, 0.1f);

/** Accelerate the physcial ball to shoot it. */



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.

First, what kind of control are you using for the player?

The way that I would do it is to detect the mesh collision, then apply a force to the ball

ball_phy.applyForce(/* Direction and magnature of force in Vector3f */, /*Location of players feet in Vector3f */);

1 Like