AddForce not working on Y

Hi, so I made an enemy that should jump at player when he is near “attack” range, I used rigidbody.AddForce to do that. When I add force x and z works perfectly but when I do y it doesnt do anything.

Code:
if (states == theState.attack)
{
if (Vector3.Distance(transform.position, player.transform.position) > 10f)
{
states = theState.run;
agent.enabled = true;
}

            transform.LookAt(new Vector3(player.transform.position.x, transform.position.y, player.transform.position.z));
                   
agent.enabled = false;

//Buggy Part
 rigi.AddForce((player.transform.position.x - (transform.position.x)), 10f, (player.transform.position.z - (transform.position.z)), ForceMode.Impulse);
            agent.enabled = true;
            StartCoroutine(noVelocity());
            states = theState.run;    
        }

AddForce doesn’t work like “moving it up by 10 on the y axis” as you wrote.

Instead, you have to specify a direction (in your case Vector3.up if you want it to always go up, or transform.up if it should consider object rotation) and multiply that by a force value.


Here’s the difference between transform.up and Vector3.up:
193926-directions.png


Use something like this instead:

rigidBody.AddForce(Vector3.up * force, ForceMode.Impulse);

Hope this helps!

Hi, I tried " rigi.AddForce(transform.up * 20f, ForceMode.Impulse);" it but it doesnt seem to work. Do you got other solutions? Cheers