How to move collection with game object and subcollection?

I have a “bow” collection:
bow

Then I have an “archer” collection, which has the bow:
archer

Then I have the main collection with an archer in it:
main

I need to move the archer with input keys up or down, but the following code moves only archer - the bow doesn’t move with it.

function on_input(self, action_id, action)
local position=go.get_position()
local new_dir=vmath.vector3()
if action_id==hash("up") then
	new_dir=vmath.vector3(position.x,position.y+3,0)
	go.set_position(new_dir)
elseif action_id==hash("down") then
	new_dir=vmath.vector3(position.x, position.y-3., 0)
	go.set_position(new_dir)
end

end

Bow must be moved with archer. What should I do?

You should move the bow inside the archer’s GO.
Keep in mind that you cannot move “the collection” itself in code, a collection is just a container.
So, all manipulations you should do with GO.

I can’t move it inside GO, it doesn’t allow me

1: why bow is a collection and not a game object?

2: you cannot move sprite components inside a GO, you must move the GO itself

3: if it is possible I would go with two GO’s, one for archer and one for bow and then a collection containing a root GO with inside these two GO’s. In this way you move the root GO to move together the archer and the bow. And, if you want to move only the bow, you move the bow GO.

I hope this make sense to you.

Ciao!

2 Likes