- Home /
 
transform.TransformDirection not working -- WHAT IM MISSISNG?
I can't see what i missing, it looks like the direction in y axis is working but not working for x and z ones.
IMAGE1: Projectiles are going down IMAGE2: Projectiles are going up
 Rigidbody currentProjectile;
 currentProjectile = Instantiate(Projectile.GetComponent<Rigidbody>(), transform.position + (transform.forward), enemy.transform.rotation) as Rigidbody;
 
 currentProjectile.velocity = transform.TransformDirection((enemy.transform.position - transform.position).normalized * Projectile_velocity);
 
              Why do you use TransformDirection? I believe you want to use a world-space vector to set the velocity of your bullet. 
Answer by Bunny83 · Jun 15, 2019 at 02:56 PM
Like Hellium said in the comment, this part:
 (enemy.transform.position - transform.position).normalized
 
               already represents a world space direction vector between your player and the "enemy" object. The velocity vector of a rigidbody also represents a worldspace direction. TransformDirection would expect a local space vector as input and outputs a worldspace direction. Since you input a worldspace direction the result is just nonsense. So just do:
 currentProjectile.velocity = (enemy.transform.position - transform.position).normalized * Projectile_velocity;
 
              Your answer
 
             Follow this Question
Related Questions
Problem with Shooting Accuracy 0 Answers
Shooting script C# 1 Answer
How to make the npc face the player. 2 Answers
Control amount of bullets 2 Answers