- Home /
Question by
mickeeee · Mar 25, 2016 at 05:51 PM ·
rotationquaternionangle
Clamp rotation
Hi all! I want to clamp my characters rotation while doing a wallrun. So that you can only look straight with the wall to 90 degrees out of the wall. The code I am using is clamping it but with the same world angles all the time. So if I am running another wall angled differently the same "world angles" will be clamped. How do I make them relative to the character so that it can be applied to any wallrun?:
Quaternion ClampRotationHorizontal (Quaternion q, Quaternion characterRotation) {
q.x /= q.w; q.y /= q.w; q.z /= q.w;
q.w = 1.0f;
float angleY = 2.0f Mathf.Rad2Deg Mathf.Atan (q.y);
angleY = Mathf.Clamp (angleY, 0f, 90f); q.y = Mathf.Tan (0.5f Mathf.Deg2Rad angleY);
return q; }
Comment