I want to rotate an object 90 degrees, the object is facing upwards and I want it animating to the right, I have this code in “init” : go.animate(".", "rotation", go.PLAYBACK_ONCE_FORWARD, vmath.quat_rotation_z(-90), go.EASING_LINEAR, 4)
But when I run, it gives me weird behaviour, it acts as if it’s moving away (scaling down) and then it goes back, rotate to opposite direction, I don’t really understand what’s going on.
I used radians(1.57) but there still some illusion of the object being scaled down and the back up, not sure if it’s happening or just my imagination.
Also I’m unable to get the rotation for comparison, I do this:
if go.get_rotation() >= -1.57 then
print("right")
end
Could you please post the full thing? It’s unclear where the self is coming from. You either need to pass in self to the rotate function or have it available in the enclosing scope where you declare the rotate function.
go.property("speed", 4)
local rotate
function init(self)
rotate()
end
rotate = function()
go.animate(".", "rotation", go.PLAYBACK_ONCE_FORWARD, vmath.quat_rotation_z(-1.57), go.EASING_LINEAR, self.speed)
end
There is a property “euler” that you can use to express rotations in Euler angles. Simpler if you just wanna do z rotation. Animate property “euler.z”.
The rotate function has no reference to self. self is passed to the init() function, but you need to pass that along to rotate() as well:
local rotate
function init(self)
rotate(self)
end
rotate = function(self)
go.animate(".", "rotation", go.PLAYBACK_ONCE_FORWARD, vmath.quat_rotation_z(-1.57), go.EASING_LINEAR, self.speed)
end