Rotate 2D missile in direction of flight?

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.

Vector2 direction = (zapTarget - zapOrigin).normalized;

float rotSpeed = 10f;

Quaternion toRotation = Quaternion.LookRotation(Vector3.forward, direction);

missile.transform.rotation = Quaternion.RotateTowards(attacker.missile.transform.rotation, toRotation, rotSpeed);

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.

You can manually calculate the z angle:

var zAngle = Mathf.Atan2(direction .y, direction .x) * Mathf.Rad2Deg;
missile.transform.rotation = Quaternion.Euler(0,0,zAngle);

If your missles still dont face the correct rotation, it means your missile sprite is rotated or something.

Pretty sure there are solutions using the Quaternion class too:

Cheers

If your missile points UP, then just set the transform.up to your motion, as long as the motion is above a certain amount, something like:

if (movementVector.magnitude >= 0.05f)
{
  missileTransform.up = movementVector;
}

That’s it.

If your missile points right, then assign the movement to transform.right instead.

Or do the math with Atan2(), same end result really.

See my attached missile-chases-you game package.

9072451–1255234–MissileTurnTowards.unitypackage (12.1 KB)

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.

Thanks again! I really appreciate all the help.