Hello, I’m trying to rotate an object to the same angle as another object using Quaternion.RotateTowards
. This works fine when I just flat-out set the rotation of the object to that of the target - no problems there. However, I also need to preserve the Y axis - and every time I try this, it goes weird and the object will only rotate a microscopic amount:
The code I’m using is this:
if (rayObjectHit != null)
{
targetRotation.x = rayObjectHit.transform.rotation.x;
targetRotation.z = rayObjectHit.transform.rotation.z;
}
transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.Euler(targetRotation), Time.deltaTime * playerRotateSpeed);
I’m assuming that injecting the target rotation like this is a bad idea - but I’m honestly out of ideas.