- Home /
Rotate a Object, but with rotation values
I have a kind of strange question, but I hope someone can give me a good hint...
To the topic:
I have a gyroscope sensor, which collects the rotation position of the attached object every 0,1 second and stores the rotation values as a Vector3. So I have some sort of json file like this:
{"x":357.0,"y":180.0,"z":11.900009155273438},{"x":357.0,"y":180.0,"z":11.900009155273438},{"x":360.0,"y":180.0,"z":12.000009536743164},...
it contains the transform.rotation of the object in 0,1 second time steps.
If I just use transform.rotation to set the rotation from the sensor, the unity object is rotation the correct way, but it is not rotating around itself:
void Update () {
transform.rotation = Quaternion.Euler(rotation);
}
I do change the rotation variable every 0,1 second to the next from the json file.
With that the rotation works fine, but the object is not rotating around it self, but around it local origin.
But I want the object to rotate around it self (with Transform.RotateAround and the center of mass of the object?).
how can I transform the stored Transform.Rotation values from the json file to fit Transform.RotateAround. Maybe there is another way to accomplish this?
Answer by Kudorado · Jan 07, 2019 at 10:42 AM
I'm not really understand your question but i think this might help you:
void Update () {
transform.rotation = Quaternion.Slerp(transform.rotation,
Quaternion.Euler(rotation), Time.deltaTime);
}
Thanks for the answer, I was a bit to sleepy when I made the Question. I tried to make it more clear. Sadly Quaternation.Slerp does not work the way I want it to.
Answer by manderda · Jan 08, 2019 at 08:41 AM
I was able to find a solution to my problem. I guess I didn't understood how rotation is handles in Unity. I could "fix" the local origin of my object with this trick: https://www.youtube.com/watch?v=6qwjyypHcj8
And with
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(rotation), Time.deltaTime);
the rotation is looking smooth now. Thank you @Kudorado!