Player vehicle spins rapidly when facing straight up or straight down

Hey guys, I’m trying to make my player character rotate slowly to face whichever direction the player is facing (i.e, the player looks to the left, and the vehicle rotates towards that direction). Everything is working exactly as I want it to, but when the player’s vehicle faces straight up or straight down, it just spins at high speed. Here’s my code for rotating the player vehicle:

Vector3 targetDir = dirRef.transform.position - shipDirRef.transform.position;
float step = newSpeed * Time.deltaTime;
Vector3 newDir = Vector3.RotateTowards(transform.forward, targetDir, step, 0.0f);

transform.rotation = Quaternion.LookRotation(newDir);

dirRef is the direction the player is looking in, and shipDirRef is the direction the ship is facing.

Any help would be appreciated!

EDIT: I ended up using Quaternion.Lerp. For anyone else needing assistance, here is my solution:

transform.rotation = Quaternion.Lerp(transform.rotation, cam.transform.rotation, Time.deltaTime * newSpeed);

This replaces the entire block of code shown above. cam is the main camera.

Eventually try a different method.

You could try Quaternion.Lerp. Here is a link that could help you: How can I lerp an objects rotation? - Questions & Answers - Unity Discussions