Proper Variation of this code, to work with any UP normal;

if(newVelocity.magnitude > 0) {
Vector3 up = transform.up;
Vector3 desiredLookPos = seekPos;
desiredLookPos.y = transform.position.y;
Vector3 desiredLookDir = desiredLookPos - transform.position;
desiredLookDir.Normalize();
float rotationDeltaInRadians = m_rotationSpeed * Time.deltaTime;
Vector3 newForwardDirection = Vector3.RotateTowards(
transform.forward,
desiredLookDir,
rotationDeltaInRadians,
0.0f
);
transform.forward = newForwardDirection;
transform.up = up;
}

So, basically the above code works all fine and well, minus the transform.up located at the bottom, was a temperary fix to something;

anyways, basically the character is suppose to rotate towards the direction of a point, and its working quite well, however I come to a point where my character has an upside down UP axis -1, instead of 1, and basically, that messes everything up; because now he rotates the opposite direction while upside down, where as when up-right he doesnt rotate at all(at least since I added the transform.up = up; )

is there anyone on here who can help me out of this pickle, and get me the right calculations to make him rotate problem, no matter if his UP normal is 0,1,0; or 0,-1,0 ?? please!

would be a great thing, and I suppose I can even offer a $5 reward.

var up = transform.up;
var lookRot = Quaterion.LookRotation(desiredLookPos - transform.position);
var axisAngles =transform.rotation.eulerAngles;
axisAngles.y = Quaternion.RotateTowards(transform.rotation, lookRot, (m_rotationSpeed * Mathf.Rad2Deg * Time.deltaTime)).eulerAngles.y;
transform.rotation = Quaterion.Euler(axisAngles);

var up = transform.up;
var lookRot = Quaternion.LookRotation((seekPos - transform.position)*up.y);
var axisAngles =transform.rotation.eulerAngles;
axisAngles.y = Quaternion.RotateTowards(transform.rotation, lookRot, (m_rotationSpeed * Mathf.Rad2Deg * Time.deltaTime)).eulerAngles.y;
transform.rotation = Quaternion.Euler(axisAngles);

this appears to have fixed it. Mike was the closest, so Mike, if you read this again, let me know and I will give you $5.00 :smiley: Just need your paypal email.

I don’t know why it’s rotating to the wrong side when the object is upside down, but probably the version below may solve the problem - it uses Quaternion.RotateTowards instead of Vector3.RotateTowards, thus can be applied directly to the object rotation:

    if(newVelocity.magnitude > 0) {
         Vector3 desiredLookPos = seekPos;
         desiredLookPos.y = transform.position.y; // kill any height difference
         // find the desired rotation
         Quaternion lookRot = Quaternion.LookRotation(desiredLookPos - transform.position);
         // and rotate a little in its direction each pass 
         transform.rotation = Quaternion.RotateTowards(transform.rotation, lookRot, m_rotationSpeed * Time.deltaTime);
    }

Notice that m_rotationSpeed in this case is expressed in degrees per second (don’t know if the previous one was in radians/second)

EDITED: My bad! Quaternion.LookDir really doesn’t exist: it should be Quaternion.LookRotation - answer fixed.