Rotate to mouse position not working when rigidbody moves

I’m using the below code to rotate my player to face the mouse position. It works great up until I move the player via AddForce

Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);
Plane p = new Plane( Vector3.up, transform.position );
if( p.Raycast( mouseRay, out float hitDist) )
{
    Vector3 hitPoint = mouseRay.GetPoint( hitDist );
    Quaternion newRotation = Quaternion.LookRotation(hitPoint);
    transform.rotation = Quaternion.Slerp(transform.rotation, newRotation, 10 * Time.deltaTime);
    Debug.DrawRay(transform.position, hitPoint, Color.green);
}

Then it does this:

The code is running in FixedUpdate along with the movement code.

Why would Rigidbody movement offset the aim code?

Hello @ayockel90,

When you hit the plane with your mouse you get a hitPoint which position is calculated with world space, in order words imagine a line starting from the center of your screen and going to your hit point, that’s the direction you apply to your ship, to make your ship rotate towards the mouse you should define a vector direction and then rotate your ship toward that direction:

Vector3 direction = hitPoint - transform.position;
Quaternion newRotation = Quaternion.LookRotation(direction, transform.up);
 
Debug.DrawRay(transform.position, direction, Color.green);

if you draw the vectors it would be easier to understand, let’s take a paper and a pencil and draw your vectors:

The green vector was what you were applying to your ship and the direction (which is the hitpoint - the ship position) is in yellow and is the right direction you needed

To understand how vector works you can simply follow the green line with your finger and when you are at the tip, you go to the direction of the blue line (but the opposite direction because we did a substraction) and so you find your vector direction (from position (0,0) to your finger)