Peculiar. localRotation should give you at least a Quaternion. What, more precisely, are you trying to do? (I don’t have high hopes of being able to figure anything out, but have had to muck around with rotations a bit lately, so I find the topic interesting…)
EDIT: Good morning, ESB - read the whole post, maybe? Yes: picking the x variable out of a Quaternion is mostly useless. They are something akin to dark magic…
Well, i work at a little non physics based flying engine. I´m still battling with the basics of Javascript, and i battle especially with the basics of everything movement and rotation related. This flying thingie here is my testproject to learn this basics
What i try to achieve is to retreive the Z rotation of the airplane. And when it is not zero i want to rotate it back to zero when the user doesn`t press left or right. This actually already works with retreiving eulerAngle.z. But this eulerAngle.z flips to 180 from time to time. And that makes trouble with especially flying a looping then. At the zenith the Z eulerangle flips from 0 to 180, and my code to rotate the airplane back starts to do his job. Which kills the looping. So i need another way to retreive the local angle. Means when there is a way
This issue becomes also interesting when i add a compass. A compass usually goes from 0 to 360, and doesn`t flip at 180 degrees
Hm, dunno if it makes sense to attach the whole script. It is in the middle of the process, and lacks a few essential features i want to add. And is of course surely full of mistakes
In essential the current crucial part is:
rotationz=transform.eulerAngles.z;
if ((rotationz >=1) (rotationz < 180)) transform.Rotate(0,0,Time.deltaTime*-50);
if ((rotationz >=1) (rotationz > 180)) transform.Rotate(0,0,Time.deltaTime*50);
}
I need to get rid of the eulerAngles, or have to add two more lines of code to work around the 180 degree issue …
Just to see if I understand. You only want the airplane to rotate around the z-axis while the user is pressing left or right? As soon as user input stops, the plane should just stop rotating? I might be completely off or misunderstanding you here, but wouldn’t it suffice to just make sure you only alter/add to the z rotation while you have user input?
But not facing north. I want the airplane to face upwards. Until i fly a curve. Then the airplane rotates sidewards a bit, and rotates back to straight when i release the button
Just to make sure that we don`t drift away from the core problem. My problem is still the eulerAngle rotation of the object. Which flips to 180 from time to time. I need to retreive a local rotation instead, that has fully 360 degrees
Yes… What I was thinking is you might not have to muck around with the 0/180 thing at all, just having some set base rotation or world-related direction that the plane should return to when there is no input… But right now, I’m afraid my mind’s drawing blank after blank. Not enough coffee input yet, I think.
Hehe, they are a computationally cheaper way of representing a rotation than doing it by matrix. Its almost always a scalar and a normalized vector in the form of
w,(x,y,z).
But im afraid im no good with the issue at hand, just thought i’d chip in
So… I’ll keep on rambling with no clear solutions! (I am thinking of how to do something similar for a project of my own, so it’s Relevant To My Interests…)
What I’d be wanting to achieve is to make the transform straighten up after user input is done (“head” up, “feet” down, so to speak).
I think I’d be inclined to, once the user input stops, ask the transform to rotate back to a rotation where the relevant angle (up pointing in the global up-direction in my case) is 0, with something like
Can you use Vector3.Angle to get the angle between the plane’s transform.up and Vector.up (ie, the global up direction)? This won’t tell you whether the plane is rotating left or right, but you will already have needed that information to tilt the plane in the first place.
Ah, but i would need the information if it is left or right. Else i rotate into the wrong direction
Thanks anyways. Have solved it by adding the two missing lines of code now instead to compensate the 180 degrees flip of the euler angle
Only a bit disturbing thing is that this way my airplane rotates to upwards down when the angle is bigger than 90 degrees. But i can live with that. At least for now. I`m still a rookie, battling with the basics
rotationz=transform.eulerAngles.z;
if ((rotationz >0) (rotationz < 90)(!Input.GetButton ("Horizontal"))) transform.Rotate(0,0,Time.deltaTime*-50);
if ((rotationz >0) (rotationz > 270)(!Input.GetButton ("Horizontal"))) transform.Rotate(0,0,Time.deltaTime*50);
if ((rotationz >180) (rotationz < 270)(!Input.GetButton ("Horizontal"))) transform.Rotate(0,0,Time.deltaTime*-50);
if ((rotationz <180) (rotationz > 90)(!Input.GetButton ("Horizontal"))) transform.Rotate(0,0,Time.deltaTime*50);
A way to retreive the separated Quaternion angles would be neat