I have humonoid witch contains a lot of children game objects. I want to flip it when it walk back. if i try to make negative scale i’m getting error “Vector passed to go.set_scale contains components that are below or equal to zero”.
if i rotate it over y by 180, then z order also flips wich is unsuitable
Are you manually setting the z distance of each component once to make sure their draw order is correct?
yes, they have different z
For sprites, you have sprite.set_hflip, but for the game objects, it should suffice to loop over the game objects and move them relative their parents position. Something like this:
local function flip(names, left)
-- skip the first node (the top parent)
for i = 2, #names do
local name = names[i]
local pos = go.get_position(name)
go.set_position(vmath.vector3(-pos.x, pos.y, pos.z), name)
sprite.set_hflip(name .. "#sprite", left)
end
print("flip ", left)
end
function init(self)
self.timeout = 0.5
self.timer = self.timeout
self.left = false
self.names = {"parent", "child1", "child2"}
end
function update(self, dt)
self.timer = self.timer - dt
if self.timer < 0 then
self.timer = self.timeout
self.left = not self.left
flip(self.names, self.left)
end
end
If you are setting the z in the editor then collect them, and reset each component z when you flip with your method. You have to remember that Defold is a 3d engine under the hood. It makes sense that in 3d space the z order would be flipped by doing what you are doing, but you can reset the z-order again each flip to make it look right. You can make a simple manager to deal with all of this. I’m not sure of a better method than needing to do a little extra busy work each flip.
Thanks for reply! If its was a way to iterate over children, i could do that recoursively. May be You could add something like go.get_children() ?