setLocalRotation() not working as expected


I did a little rotation testing code and discovered an effect, which is strange to me. Following code does a rotation to my spatial, but I don’t understand why, in my opinion, the spatial should not rotate, because I revert the rotation in the last line:

[java] public void update(float tpf) {

Quaternion backupRotation = spatial.getLocalRotation();

spatial.rotate(0f, someRotation, 0f);




Why does it rotate anyway?

Kind regards,


getLocalRotation() actually retrieves a reference, so when you call spatial.rotate() you’re indirectly also modifying the backupRotation which you stored.

An easy fix would be something like

[java]Quaternion backupRotation = spatial.getLocalRotation().clone();[/java]

1 Like

Thats it!

I thought getLocalRotation() returns already a copy…

Thank you very much!