Alternative to quaternions (SOLVED)

You should be aware of a few things when using go.animate on euler.z: https://forum.defold.com/search?q=euler

I would recommend that you get used to using quaternions for rotation. Here’s a discussion about euler vs quaternions: Rotation and moving forward ? simple?

Here’s another alternative, although it’s not a one-liner:

-- in this example we track the angle using a go.property
go.property("angle", 0)

function init(self)
	-- since the angle is defined using go.property we can use it in calls to go.animate
	go.animate("#", "angle", go.PLAYBACK_LOOP_FORWARD, 360, go.EASING_LINEAR, 1, 0)
end

function update(self, dt)
	-- here we set the rotation around the z-axis every frame using the angle
	go.set_rotation(vmath.quat_rotation_z(math.rad(self.angle)))
	
	-- we could also do it like this (although go.set_rotation is the recommended way)
	--go.set(".", "euler.z", self.angle)
end
4 Likes