Mathf.Clamp not clamping properly
Now im trying to clamp a x axie in character but it's not working. I tried searching but it only scraches my head more. Please help me if you can.
void MoveRotation ()
{
//Oblicz rotacje jako vector 3D (tylko w osi poziomej)
float yRot = Input.GetAxisRaw("Mouse X");
Vector3 Rotation = new Vector3(0f, yRot, 0f) * sensitivity;
//Wyślij rotacje
exec.Rotate(Rotation);
//Oblicz rotacje kamery jako vector 3D (tylko w osi pionowej dla kamery). Poźniej zmodyfikuje do oczu, głowy, szyi, ciała itd.
float xRot = Input.GetAxisRaw("Mouse Y");
Vector3 CameraRotation = new Vector3(xRot, 0f, 0f) * sensitivity;
Debug.Log("Before: " + CameraRotation);
CameraRotation.x = Mathf.Clamp(CameraRotation.x, -45f, 45f);
Debug.Log("After: " + CameraRotation);
//Wyślij rotacje
exec.RotateCamera(CameraRotation);
}
And the other when im finilizing it.
//Bierze vector Rotacji x
public void RotateCamera(Vector3 CameraRotation)
{
camerarotation = CameraRotation;
}
void PerformRotation ()
{
rb.MoveRotation(rb.rotation * Quaternion.Euler(rotation));
if(Kamera != null)
{
Kamera.transform.Rotate(-camerarotation);
}
}
Please ignore comments - they are only for me so... If you want other parts or scripts that can effect of the problem I can send them as well. Thanks for support.
Comment
Your answer
Follow this Question
Related Questions
Character movement that ends with a specific facing 0 Answers
Why does this affect the rotation.z 1 Answer
Arrow mechanic like soccer star 0 Answers
Character Rotation 0 Answers
Struggling to get the rotation the player is moving in. 1 Answer