Game object's scale affects its world rotation [DEF-2032] (SOLVED)

  1. Create Game Object
  2. Set rotation via editor fields (for example z = 90)
  3. Add script to this GO and print result of go.get_world_rotation()
  4. Change scale of game object
  5. Print go.get_world_rotation() again - quaternion value will change.

WTF? (:

Editor Version 1.2.85, Windows 7 x64

2 Likes

For example:
I want to rotate a vector by go.get_world_rotation()
It will work only if go has uniform scale.

PS Can i get x, y, z angle value from quaternion? If no, can you add this function?

@Ragnar_Svensson and @Andreas_Tadic: This should be your domain. Expected behaviour or not?

Very strange that scale affect to the rotation quaternion

Yes, it’s a bug. The world rotation is calculated on the fly and it does not factor out the scale, as it should do. There is no builtin function in vmath to convert a quat to the euler angles, but there definitely should be. I added both issues as: DEF-2032

5 Likes

I believe I have re-encountered this bug. When I do

rot=go.get_rotation()
rot.z=rot.z+10
go.animate(".", "rotation", go.PLAYBACK_LOOP_FORWARD, rot, 1, 5, 0)

The objects gets larger and larger as it spins. That’s undesired, right? (I feel like “legitimate bug discovery” is a pretty big step towards truly understanding a piece of software)

The strange behaviour you encountered is not actually a bug, but a misconception of how rotations work in the engine.

We represent all rotations as quaternions in the engine, a bit different than the more broadly known “euler rotations”. Just changing the Z-value of a quaternion can result in strange results if not fully aware what it means. There are great explanations online how quaternions work so I will not go into details here.

But a quick and short answer to how to solve it in your specific case:

rot = go.get_rotation()
local radians = math.pi / 180 * 10
rot = rot * vmath.quat_rotation_z(radians)
go.animate(".", "rotation", go.PLAYBACK_LOOP_FORWARD, rot, 1, 5, 0)

More info: vmath.quat_rotation_z()

(I have not tested this code myself, but I think it should work. ;))

2 Likes

We also have euler! :wink:

2 Likes

Solved in Defold 1.2.158 has been released

1 Like