I know this question has been asked many times, but I’ve tried many of the suggested solutions, and none seems to work properly for me. I’m making a top-down 2D game, and I’m trying to point a missile (a game object) at its target. The origin and target locations are fixed in world space. The missile moves in a straight line from origin to target, in Update(). But for the life of me, I can’t get it to point at the target. I’ve tried several approaches.
In place of that last line, I’ve also tried: // missile.transform.rotation = toRotation;
and:
I’ve also tried the more complex code in this thread:
No matter what I try, the missile faces in one incorrect direction and remains in that direction. Can anyone suggest a better approach? I have the nagging feeling there’s a much simpler solution, because the problem seems so basic to me. Thanks in advance.
Thanks, guys! I tried Atan2(), and it worked immediately. My sprite is facing right, for what it’s worth, so I didn’t have to make any adjustments at all to @venediklee 's suggested code. @Kurt-Dekker , I also will dig into your package, because I might eventually want the missile to do more than just fly in one direction.