- Home /
Instantiating a projectile pointing at target.
Hi everyone. So I have a player and a target. I want the player to instantiate a projectile, with its rotation pointing at the target (from the player). my idea was this-
shotDirection = Quaternion.FromToRotation(transform.position, target.transform.position);
if (Input.GetKeyDown(KeyCode.Keypad1))
{
Instantiate(projectile,transform.position,shotDirection);
}
but it seems that "FromToRotation" doesn't work the way I expected it to. Can someone please advice?
Answer by syclamoth · Oct 31, 2011 at 12:36 AM
Sure- you're thinking of
Transform.LookAt(position);
However, since this actually rotates the transform (which I don't think you want to do) You may instead want this-
Quaternion.SetLookRotation(target.transform.position - transform.position);
Thanks. It did make it point with the z axis however. So I just rotated everything accordingly :)
Your answer
Follow this Question
Related Questions
Want to instantiate projectile in direction character is moving. 1 Answer
Instantiate object at position, moving in a direction? 1 Answer
Firing only a single projectile at a time, then adding a second. 2 Answers
Transform continue direction 0 Answers
Make multiple Projectiles move at the same Time... 0 Answers