Help with setLinearVelocity?

Hi all. Could anyone explain how I can use setLinearVelocity to push a ball forward? I have the following code which creates and positions a cannon ball ballPlayer in front of a spatial avatarPlayer by 1.8f and above it by 1.8f. In the final line I try to push the ball forward in the direction the ball is facing, but seems the ball is not pushed forward but in some other direction. Any help is greatly appreciated!

ballPlayer = new Geometry(“cannon ball”, sphere);
ballPlayer.setLocalTranslation(avatarPlayer.localToWorld(new Vector3f(0, 0, 1.8f), null).add(0, 1.8f, 0)); // positions the ball relative to the
ball_phy = new RigidBodyControl(1f);
ball_phy.setLinearVelocity(ballPlayer.localToWorld(new Vector3f(0, 0, 1f), null)); // push the ball foward

Because ur not using a direction vector.

Here is a simple example of using physics:


In other words, I should put the following instead? I subtract the location that’s at 1 unit in front of the ball from the location of the ball?

ball_phy.setLinearVelocity(ballPlayer.localToWorld(new Vector3f(0, 0, 1f), null).subtract(ballPlayer.getLocalTranslation())); // push the ball foward

It seems a long way around.

Why not define your desired velocity somewhere and then apply the ballPlayers rotation to it?

Okay, I think I got it. I use the character control’s getViewDirection with setLinearVelocity. That should work!