Any simple ways of keeping track of simple rotation?
I want to track my objects rotation. I will give an example so you can understand. I want to rotate an object by an amount in any direction. Once it hits that amount, it stops. The way I have it set up is basically:
if(rotatingObject.transform.rotation.eulerAngles.y < 90) { rotatingObject.transform.Rotate(Vector3.left speed Time.deltaTime); }
The issue at hand is that rotation is from 0 to 360 so sometimes if I rotate left or right it goes from 360 to 0 and I have to duct tape the code so that it works the way I want to.
What I want to know is if this is possible. I will pseudocode it a bit Have an integer of float that is the rotation being track by a positive value. So lets say the object rotates by 1 this will += 1 to that integer or something like that. Here is an example below.
public GameObject rotatingObject;
public float rotationTracking;
public float rotationGoal;
void Update()
{
rotateObject();
}
void rotateObject()
{
if(rotationTracking != rotationGoal)
{
/*I know this next line wont make much sense but it will convey the idea I am trying to get across and what i'd like to do
rotationTracking = rotatingObject.transform.Rotate(Vector3.left * speed* time.deltaTime);*/
rotatingObject.transform.Rotate(Vector3.left * speed* time.deltaTime);
}
}
Excuse the formatting, I wrote it here on the fly but have reformatted it to be more understandable. $$anonymous$$y apologies.
Answer by Gabestronaut · Jan 26, 2016 at 08:13 PM
public float curRot;
curRot += rotatingObject.transform.localRotation.x;
Answer by ShadyProductions · Jan 25, 2016 at 07:41 PM
public Vector3 curRot;
curRot = new Vector3(rotatingObject.transform.eulerAngles.x,rotatingObject.transform.eulerAngles.y,rotatingObject.transform.eulerAngles.z);
Something like this maybe? (untested).
That was not quite what I was looking for but thank you because you steered me in the right direction! I managed to figure it out testing variations of methods and found one that worked.
public float curRot;
curRot += rotatingObject.transform.localRotation.x;