- Home /
Temperary Variables
Hi, so I want to create a variable that tracks the difference in rotation of my gun every frame. I am doing this so I can use this information in order to create a swaying effect. I am trying to set up a temporary variable that stores the rotation. It is then compared to the current rotation, and I get to find out the difference. However, it seems to always return 0. Am I setting this up wrong? Also, I know that the code does not add the sway yet, I just need it to get the difference first. Thanks!
//Variables
var tempRotation: Quaternion;
var rotationDifferenceX: int;
var rotationDifferenceY: int;
//Script
rotationDifferenceY = tempRotation.y - transform.rotation.y;
rotationDifferenceX = tempRotation.x - transform.rotation.x;
Debug.Log(rotationDifferenceX);
Debug.Log(rotationDifferenceY);
rotationTarget = cameraObject.transform.rotation;
rotationTarget.y += rotationDifferenceY;
rotationTarget.x += rotationDifferenceX;
transform.rotation = rotationTarget;
tempRotation = transform.rotation;
transform.rotation is a 4D quaternion. Don't try to modify/read the x/y/z/w components unless you understand quaternions 100%.
http://answers.unity3d.com/questions/422829/how-can-a-decrease-angle-every-time-in-simple-pend.html see this link.. in on mouse drag there is diff fins in angles.. in the same way u can i think so.
Your answer
Follow this Question
Related Questions
Static var wont work 2 Answers
How can I convert this script to automatic fire? 2 Answers
Accessing other script problem 1 Answer
UnityScript How to Detect Movement from FPS Controller 0 Answers