Launch projectile from moving player in 2D


I’m creating a sidescroller in a 3D. So this means my z value always stays the same for the player’s character.

Now I want to launch a projectile from the player’s character. I’ve gone over the physics tutorial and tried to adapt it to my case, though I’m failing.

What I’m currently doing:

This function is executed on a click:

public void makeCannonBall() {

    Vector3f v3 = Player.getInstance().getLocalTranslation();

    // Get the position of the cursor
    Vector2f mouse = RePest.getInstance().getInputManager().getCursorPosition();

    Vector3f click3d = RePest.getInstance().getCamera().getWorldCoordinates(new Vector2f(mouse.x, mouse.y), 0f).clone();
    Vector2f v2 = new Vector2f(click3d.x- v3.x, click3d.y- v3.y);
    // Convert the 2d vector back to a 3d vector
    shootingdirection.x = v2.x;
    shootingdirection.y = v2.y;
    shootingdirection.z = 0f;

    Geometry ball_geo = new Geometry("cannon ball", sphere);
    ball_geo.move(0f, 1f, 0f);
    ball_phy = new RigidBodyControl(1f);

The ball is starting from the player’s character position but is not going the right direction. The direction seems to change depending on which way the character is moving. And also the ball is not moving in the z plane in which the character is moving.

Anyone can give me some info on how to do this ?

fixed it. the ball was being positioned inside the character