- Home /
Write a C# script to record GameObject rotation?
I know how to write most of the script and record to csv file. But when i play back the GameObject from the data it comes very deformed and crooked and essentially inaccurate. I am using Quaternion.Euler(gameObject.transform.localEulerAngles()) to obtain the rotation values. Is this correct?
Answer by unity_lF98_nVJe9di1A · Apr 05, 2019 at 04:13 PM
Actually all has been solved. I removed stupid Quaternion that I for some reason still kept in my code, and changed it to Vector3. The whole animation is now working. Thank you for all your help! Solution is here https://pastebin.com/jmy7LwXv
Answer by xxmariofer · Apr 05, 2019 at 01:56 PM
you want to obtain the rotation of the object? why not just use transform.rotation? if you want to store the euler angles just use transform.rotation.eulerAngles what you are trying to do in that line feels redundant but not innacurate, but you are getting the local rotation so that may be whats making it inaccurate
i tried transform.rotation and transform.localRotation and it still comes very crooked. Also is there a way to get the rotation angles EXACTLY how they appear in the inspector?, because transform.rotation values are actually different to the inspector values.
as i said transform.rotation.eulerAngles tells you exactly what is in inspector, try logging them and compare if they are logging right
Hi, just compared them and they are not logging right.
See image attached
The euler angle logged and the value in the inspector are about 360 degrees different.
Please find my code here https://pastebin.com/EPBJUPYx
Answer by Tsaras · Apr 05, 2019 at 02:20 PM
It is pretty straightforward if you record transform.rotation and then replay by setting the transform.rotation values. Unless you absolutely want euler angles for some reason.
i tried transform.rotation and transform.localRotation and it still comes very crooked. Also is there a way to get the rotation angles EXACTLY how they appear in the inspector?, because transform.rotation values are actually different to the inspector values.
Answer by metalted · Apr 05, 2019 at 03:36 PM
The inspector rotation values are in transform.localEulerAngles.
Only use this variable to read and set the angles to absolute values. Don't increment them, as it will fail when the angle exceeds 360 degrees. Use Transform.Rotate instead ~ Unity Reference
https://docs.unity3d.com/ScriptReference/Transform-localEulerAngles.html
Your answer
Follow this Question
Related Questions
transform.localRotation resets after rotation 1 Answer
Instantiate GameObject towards player 0 Answers
Adding Rotation to a Gameobject 1 Answer
How rotate only z axis of Gameobject (2D) 1 Answer
Auto leveling help 0 Answers