How to move objects in sync?

Suppose we have two GO. “first” is animated via go.animate() in it’s init():

go.animate(".", "position.x", go.PLAYBACK_LOOP_PINGPONG, 500, go.EASING_LINEAR, 1)

Also in “first”'s update() function we do:

local position = go.get_position() go.set_position(position + vmath.vector3(0, 100, 0), "second")

Because update() is called before go.animate() is evaluated and applied, “second” game object lags behind “first”.
In Apple’s SpriteKit, for example, we have other callback methods: didEvaluateActions, didSimulatePhysics, didFinishUpdate. In Defold we only have update().
So, there is no way to perfectly move objects together?

There are of course many ways of moving objects together in sync, depending on case. Just probably not this particular way.
One thing you could try is to parent one gameobject to the other and offset it y:100

Why can’t you animate both with go.animate()?

function init(self)
   go.animate(".", "position.x", go.PLAYBACK_LOOP_PINGPONG, 500, go.EASING_LINEAR, 1)
   go.set_position(go.get_position() + vmath.vector3(0, 100, 0), "second")
   go.animate("second", "position.x", go.PLAYBACK_LOOP_PINGPONG, 500, go.EASING_LINEAR, 1)
end
1 Like