It would be great to have a more simple alternative to quaternions for rotation. I had not come across them before and it was immediately daunting when reading up on them.
If you could rotate game objects using Euler angles and a relative position, it would be much simpler.
-- get current euler
go.get(".", "euler")
-- set new euler
go.set(".", "euler", vmath.vector3(0,0,20))
-- animate euler
go.animate(".", "euler", go.PLAYBACK_LOOP_FORWARD, vmath.vector3(0,0,90),go.EASING_INCIRC, 1)
-- set just z
go.set(".", "euler.z", 20)
-- animate just z
go.animate(".", "euler.z", go.PLAYBACK_LOOP_FORWARD, 30, go.EASING_INCIRC, 1)
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
Do you mean to not rotate around the center point? You could offset your sprite components or your could create a collection and have a root object that you rotate and offset a child game object from the root object.
If you select the sprite component there should be fields in the properties window that allows you to change its x,y,z. You can’t change this at run-time though.