Hi all,
I have a problem with rotating an object in following situation: The object can be rotated around the y-axis and the z-axis. So if I want to rotate it around the y-axis, I do these steps:
(1) Set rotation around z-axis to 0
(2) Rotate around the y-axis
(3) Set rotation around z-axis to the old value
I have to rotate it to 0 on the z-axis, so it keeps moving horizontally.
To do this (step (1)), I use the following code:
float f = object.getLocalRotation().getZ();
object.rotate( -f );
To rotate it back in the end (step (3)), I use this code:
object.rotate( f );
My problem now is, that the object is rotated to 0 on the z-axis in step (1), but in step (3), it doesn’t rotate by f.
I hope you understand what I want to do and that you may be able to help me, thx.
Try this:
[java]
float[] xyz = object.getLocalRotation().toAngles(null);
xyz[1] = (whatever the new y rotation is);
xyz[2] = (whatever the new z rotation is);
object.setLocalRotation(object.getLocalRotation.fromAngles(xyz[0], xyz[1], xyz[2]));
[/java]
1 Like
It is working, thank you!