Node Move to other node

Node Move to other node

Sorry but I don’t understood how works node position :frowning:
I have a player and a enemy inside a layerGame and I cannot move enemy over a locator inside player… I tried this but not works

 enemy.x = player.loc.x;
 enemy.y = player.loc.y;

how is the correct mode to move enemy over loc? sorry for noob question :pleading_face:


ok, I have resolved but I don’t know why… :confused:

  1. get the parent (layerGame) and I wrote this:

pos = parent.convertToWorldSpaceAR(player.loc.position)

  1. convert to node space:

pos = layerGame.convertToNodeSpaceAR(pos)




X and Y coordinates of nodes are relative to its parent.
So if player and enemy have different parents, this transformation with the convertTo methods is needed.

so I convert to WorldPosition with first parent node and after I convert to space with destination parent node?

Yes, exactly.

ok, now I have a sample because I cannot place a sprite in a specific position :frowning:


made a prefabs NodeB we want set NodeB to childA2 position inside LayerGame, how make this? :open_mouth: help!


something like this may work:


so, I use the parent node with convertToWorldSpaceAR and after I use convertToNodeSpaceAR with the parent destination? Is not e trouble if childA2 have other 2 parent before LayerGame?

Follow this link to know more about convertToNodeSpace and related functionalities. It explains the core principles of it in C++ engine, CC should also follow along.

1 Like

childA2 can be anywhere in the hierarchy, no matter how deep.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.