Is it possible to update Z coordinate during go.animate?

Hello.
For my 2d top-down tile map project i need to change object z coordinate (index) for depth simulation. For that purpose i use Y coordinate of each object on the map and map it to the range from 0 to 1. It works as expected so far.

The problem is - i can not update Z coordinate for objects currently updated by go.animate. This lead to an issue where animated object will overlap other objects on it’s movement path until animation is complete.

For example if i move an to some destination point

go.animate(
  go.get_id(), 
  CONSTANTS.PROPS.POSITION, go.PLAYBACK_ONCE_FORWARD, 
  destination, go.EASING_LINEAR, duration, 0, 
  function (self)
    idle(self)
  end
)

Then updating it’s z index during update will not work

function update(self, dt)
  local position = go.get_position()
  position = map_helper.z_index_for_y(position.y)
  go.set_position(position)
end

It looks like go.animate makes changes after game object update call and overrides position property.

What i looking for is some sort of callback for go.animate or post_update where i can modify animation result.

I can move objects manually inside update callback obviously, but this will introduce complexity since i really do not want to loose ability to use easing functions and handle precision issues manually.

you don’t need to update function at all. just set
destination.z = map_helper.z_index_for_y(destination.y)
before call animation function.

2 Likes

Ok. that was a waste of two hours. Thanks, it works as expected.

You could also animate “position.x” and “position.y” separately, which would leave position.z untouched.

1 Like