Smooth rotation

Hello,

I am having a bit of trouble juicifying my game, which among others involves rotating tiles. My rotation func looks like this:

self.rotation = self.rotation + 1
if self.rotation > 3 then self.rotation = 0 end
go.animate(".", "euler.z", go.PLAYBACK_ONCE_FORWARD, self.rotation * 90, go.EASING_LINEAR, 0.2) 

It works flawlessly for 3 steps but then as it goes from 270 to 0 it changes the turning direction (which is to be expected). Is there any way around this?

Thanks!

I believe you have hit a bug we have on rotation. See Euler property animation on game object (DEF-1636)

You can use vmath.lerp to smoothly animate between the rotation values and then update the rotation as the values are animated. It will require some extra code to handle the animations but it will work until the Euler bug is fixed. You can either feed in the current rotation as the start of the lerp as it animates (common practice even if it’s incorrect use) to make it go faster as it goes, or store the starting and stop for the duration of the animation to lerp smoothly.

Another option is to use Spine to animation the rotations. More overhead, but if your goal is juice/polish then you can really make special rotation animations with character (squash, stretch, anticipation, exaggeration) using Spine.

1 Like

Alright, I will try out Pkeod’s approach. I want to reserve the use of Spine for my main project, this is just something on the side to tide me over while I wait for character assets.

Thanks for the replies :slight_smile: