I am trying to rotate a square GameObject, so it appears to be standing perpendicular to the slope underneath it. However, when above a slope, the square constantly "spins"; it seems like the rotation is set and then immediately set back to 0, causing it to jitter.
I am currently using a RayCast based character controller instead of rigidbody. To change the rotation, I added the follow line of code following the vertical RayCast:
if (_raycastHit)
{
transform.rotation = Quaternion.FromToRotation(transform.up, _raycastHit.normal) * transform.rotation;
...
}
It calculates and rotates the square correctly, but I am not sure why it resets back to 0 every other frame. To avoid taking up too much space, the character controller I am using is hosted on GitHub here. Specifically, this is in the moveVertically()
method.