- Home /
Min, Max Rotation Help
Im trying to set the Min and max rotation for my camera, this my attempt.
void Update() {
//X Rotation Min and Max
if (transform.eulerAngles.x >= -15){
transform.eulerAngles.x = -15;
}
if (transform.eulerAngles.x <= -60){
transform.eulerAngles.x = -60;
}
and this is were the rotation is happening
_currentCameraRotation.x += changeInRotationX * settings.rotation.cameraRotationRate.x * Time.deltaTime;
Answer by MikeNewall · Apr 30, 2014 at 02:45 AM
You didn't state what was wrong in your question...
You can't modify the rotation components like that. Store the rotation in a local variable, clamp the values, and then reassign the objects rotation.
You can limit the value of a float between a $$anonymous$$ and max value using $$anonymous$$athf.Clamp:
//Get the current rotation
Vector3 clampedRotation = transform.eulerAngles;
// Clamp the X value
clampedRotation.x = $$anonymous$$athf.Clamp(clampedRotation.x, -60, -15);
// assign the clamped rotation
transform.rotation = Quaternion.Euler(clampedRotation);
I added this code to the update function but it doesn't seem to work?
"This is where the rotation is happening" You're just assigning the x component of a variable(Vector3), there is no rotation happening unless you're trying to assign that variable to the rotation some place else?.
Where are you getting the variable "changeInRotationX" from and how are you calculating it?
Is this done in a single script? And is it attached to your camera?
It's easier to help if you explain things a little better :p
Its okay Iv figured it out now, thanks for the help.
Answer by conceptfac · Oct 17, 2020 at 10:50 PM
Here shakes only when i rotate x axis for down! RIDICULOUS!