- Home /
Question by
VisualTech48 · Jan 29, 2017 at 12:40 PM ·
rotationquaternionsmoothclamp
Rotation - Simple Question
Hello everyone, and sorry to waste time with such a probably trivial thing, however I've ran into a problem limiting the rotation while going up and down, however with a custom smoothing script.
Any help is appriciated!
#pragma strict
var QuadMax : float[];
var CameraR : Transform;
var Speed : float = 5.0;
var Move : float;
var Addition : float;
var CoMovement : Vector3;
var Movement : boolean;
function Start () {
}
function Update () {
Move = Speed;
Movement = false;
CameraR.eulerAngles += CoMovement;
if(Input.GetKey(KeyCode.W)&& !Movement){
Movement = true;
if(CameraR.eulerAngles.x < QuadMax[0]){
CoMovement.x = Mathf.MoveTowards(CoMovement.x, (Speed + Addition), 2.9*Time.deltaTime);
}
}
if(Input.GetKey(KeyCode.S) && !Movement){
Movement = true;
if(CameraR.eulerAngles.x > QuadMax[1]){
CoMovement.x = Mathf.MoveTowards(CoMovement.x, -(Speed + Addition), 2.9*Time.deltaTime);
}
}
if(Input.GetKey(KeyCode.A)&& !Movement){
Movement = true;
CoMovement.y = Mathf.MoveTowards(CoMovement.y, (Speed + Addition), 2.9*Time.deltaTime);
}
if(Input.GetKey(KeyCode.D)&& !Movement){
Movement = true;
CoMovement.y = Mathf.MoveTowards(CoMovement.y, -(Speed + Addition), 2.9*Time.deltaTime);
}
if(Movement && Addition < 0.9){
Addition += 0.55*Time.deltaTime;
}
else{
if(Addition > 0){
Addition -= 1.5*Time.deltaTime;
}
//CoMovement = Vector3.MoveTowards(CoMovement, Vector3(0,0,0), 2* Time.deltaTime);
CoMovement.x = Mathf.MoveTowardsAngle(CoMovement.x, 0, 2*Time.deltaTime);
CoMovement.y = Mathf.MoveTowardsAngle(CoMovement.y, 0, 2*Time.deltaTime);
}
//CameraR.eulerAngles = Movement;
}
Comment
Your answer
Follow this Question
Related Questions
How to Clamp a Quaternion Camera Rotation? 0 Answers
Lerp with raycast hit.normal? 2 Answers
Smoothing the characters rotation with Lerp 2 Answers