- Home /
Bank Camera Based On Rotation Delta
Hello, I am trying to put together a simple banking effect when the camera turns left or right. The Camera is not able to look up or down, the only angle that changes is the y. I have tried using this to find the angle delta and apply it to the z axis;
var mainCamera : GameObject;
var lastCamRotation : float;
var currentCamRotation : float;
var angleDifference : float;
var speedAdjust : float;
function Start (){
lastCamRotation = mainCamera.transform.localEulerAngles.y;
}
function Update (){
currentCamRotation = mainCamera.transform.localEulerAngles.y;
angleDifference = Mathf.DeltaAngle(currentCamRotation,lastCamRotation);
lastCamRotation = currentCamRotation;
mainCamera.transform.localEulerAngles.z = angleDifference*speedAdjust;
}
Due to the method of moving being used on a touchscreen, I cannot use any getAxis functions or anything that is specific to mice. There are no errors with this script in the editor, the problem is that it is very rough input. Even when I had smoothed it it would vibrate wildly while turning left or right. Could anyone help me figure out how to make this script work smoothly or find a better way to simulate banking when turning left or right? Any help would be greatly appreciated!!
Answer by LyanApps · Apr 25, 2013 at 03:07 AM
I would suggest: http://docs.unity3d.com/Documentation/ScriptReference/Quaternion.RotateTowards.html
//Save the current Rotation
currentRotation = transform.localRotation;
//Calculate the rotation you want to have
targetRotation = Quaternion.Euler(transform.localEulerAngles.x, transform.localEulerAngles.y, transform.localEulerAngles.y + angleDifference);
//Use RotateTowards to find the in between rotations based on angular step
transform.localRotation = Quaternion.RotateTowards(currentRotation, targetRotation, speed*Time.deltaTime);
Your answer
Follow this Question
Related Questions
Smooth camera rotation velocity. 0 Answers
Turning the camera down smoothly while running 2 Answers
Smooth tilting rotation on slopes like cars? 1 Answer
Slight Problem in the Camera Rotation Script 0 Answers
Rotate around object smoothly 1 Answer