So, I’m having this problem where my mathf.clamp works for the min value, but not on the max. To be more specific, everytime I rotate my object (bound to mouse input) below 0, it teleports back to the min value set for the clamp. I wish I could show you in a video.
I am trying to move a characters arm (with gun) up and down on the x axis.
I’ve been looking all over the web, but can’t find what I did wrong.
Thx in advance!
Code:
using UnityEngine;
using System.Collections;
public class Right_Arm_Rotator : MonoBehaviour {
private float rotateSensitivity = 2f;
private float mouseInputNumber;
private Vector3 eulerAnglesStored;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
mouseInputNumber = -Input.GetAxis("Mouse Y") * rotateSensitivity;
transform.Rotate(mouseInputNumber, 0, 0);
eulerAnglesStored = transform.eulerAngles;
eulerAnglesStored.x = Mathf.Clamp(eulerAnglesStored.x, -100, 30);
transform.eulerAngles = eulerAnglesStored;
}
}