[SOLVED] Moving sprites don't follow the z axis when being rendered

I noticed a problem while I was recording a test:


The sprites render differently while moving, where the moving sprites are rendered on top of static sprites.

I’m using a z axis of 0 for all the children of the moving component, and I have code in the update functions of each of them which updates the z value of each one

local z_dist = -((go.get_position().y - self.position_offset.y)/10000)
go.set(".", "position.z", z_dist)

position_offset is just a value to allow me to move it up/down without moving it back/forward and is always at 0 when the characters are moving.

I am using an animate function to move the characters

go.animate(".", "position", go.PLAYBACK_ONCE_FORWARD, pos, go.EASING_LINEAR, time, 0, function()
	stop_walk(self)
	self.is_busy = false
end)

Is there anything I’m missing? If not, is there anything that I can try to potentially debug this?

Remember that go.animate() will animate both x, y AND z value of the position. Which z-value do you set in the pos that you pass as the to argument to go.animate()?

1 Like

Ah, this is correct! I completely overlooked the fact that it was animating the z-value going back to zero, thanks for pointing that out!
I’ll change it to animate the x and y positions only, hopefully that’ll fix everything

1 Like

It’s working! Thanks for the help


:grin:

2 Likes