- Home /
Clamp rotation of value from other object
Hi All,
I'm trying to find a better way to clamp a value that I'm pulling from another object.
public GameObject playerCamera;
private float rot;
private float rotationZ = 0f;
void Update() {
rot = playerCamera.transform.localEulerAngles.y;
rotationZ = Mathf.Clamp (rotationZ, 25, 360);
transform.localEulerAngles = new Vector3(0, 0, -rot);
}
So here I'm matching the y value of the camera to the gameobject, which works. But as I'm pulling in that value, I can't also pull in the clamp value. Does that make sense?
Where I have my new Vector3(0, 0, -rot); the value -rot which is what I'm using to match the camera rotation is also where I'd need to put the clamp value rotationZ. So I can't do both match camera rotation AND clamp the value?
I can do the clamp like this
if ((rot > 0 && rot < 25) || (rot > 335 && rot < 360))
But was wondering now if it's possible to use Mathf.Clamp to do the same thing?
Your answer
Follow this Question
Related Questions
How to predict position of object before transform.translate will apply? 1 Answer
How to clamp the rotation of this? 0 Answers
Rotation not working as expected 0 Answers
Why is this rotation acting odd? 0 Answers
How to get a proper ramming effect? 1 Answer