- Home /
Not shooting in desired direction
Hi everyone,
I have a topdown view in my game, for that I rotated my cam 90° around the X axis. Now I have a "shooting" script.
GameObject projectile = (GameObject)Instantiate(Resources.Load("projectile"),spawn.position,Quaternion.identity);
projectile.transform.LookAt(cursor);
projectile.rigidbody.AddForce(transform.forward* bulletSpeed * Time.deltaTime);
Destroy(projectile,5f);
The Problem is, my projectile is not moving to my desired direction "forward" its moving to the north, but my "gun" is facing to the right. I think that is because of my camera rotating right? So how do I recalculate the direction ? I also tried TransformDirection and so much more nothing works for me:/
THanks in advance
Answer by Eric5h5 · Jun 24, 2013 at 06:22 PM
Probably you want to use projectile.transform.forward, not transform.forward, since transform.forward is the forward direction of whatever the script is attached to rather than the projectile.
Oh yeah sorry I already tried that, its also not working, nothing changed.