Hello guys, here is the problem,

I am making a soccer game where a player can shoot a ball in front of him, just like in real soccer.

The problem is, when I shoot, the ball does not go straight forward like planned, but goes diagonnaly : at 5 (clockwise) when looking right, and at 7 when looking left. Here’s a screenshot for better comprehension.

*green arrows : wanted direction
*red arrows : actual and unwanted direction

Here is the code of the shoot function :

void PassBall(float passCount)
    {
        ball.Pass(passCount * player.transform.forward);
        //passCount is an int variable that increments each a pass occures. It is used the define the power of the shot
    }

The function above is used in the playerController Script, when shot button pressed. It calls the following function, which is defined in the ball script :

   //Passes the ball
    public void Pass(Vector3 passForce)
    {
        if (!ballActive)
        {
            transform.parent = null;
            gameObject.AddComponent<Rigidbody>();
            Ball.GetComponent<Rigidbody>().AddForce(new Vector3(passForce.x * 5,passForce.y *5 + angle,passForce.z * 5), ForceMode.Impulse );
         } 
    }

I can’t figure out what Im doing wrong, can u please bring some help ? Thanks in advance for ur attention.

Hi! Why do you sums pass force + angle?
AddForce(new Vector3(passForce.x * 5,passForce.y *5 + angle,passForce.z * 5), ForceMode.Impulse );
Check if the Line Code was Right

try to uncheck gravity on ball’s rigidbody component and then see what happens.