- Home /
Moving object relative to another objects axis
Hi, im having a hard time figuring out how to make object "last" be all the time right behind places[0] object. The script is not working how i'd like it to work.
It stays 2 units behind in world space z axis and i want it to be behind 2 units in places[0] z local axis.
Basically i don't want this to happen("last" object is the one which is not in the row and places[0] object which is last cube in the row):
`last.transform.position = new Vector3(places[0].transform.position.x , places[0].transform.position.y , places[0].transform.position.z - 2`);
Answer by DanielleSisserman · Aug 12, 2018 at 10:55 AM
I'm not really understanding but it sounds like you want to make "last" a child of places[0].
if for some reason you dont want to do that than use localPosition:
`last.transform.position = new Vector3(places[0].transform.localPosition.x , places[0].transform.localPosition.y , places[0].transform.localPosition.z - 2`);
Okay, new question, What could be the problem that child is not moving along with parent object? p.s. I don't have rigid body attached to it.
Answer by CakeMonsey · Aug 12, 2018 at 11:04 AM
If you thought to do that, you understand the question. I tried all of that already. If i make last a child, then it still does the same thing and nothing changes for some weird reason. If i use local position, it still doesn't work. "last" is just a lot more away (not 2 units) and its not in the same direction,
https://www.youtube.com/watch?v=mSq7pmRV6Oc&t=0s&list=LLbVvV56b9cjXZ8c8WlL4hpg∈dex=28 0:53 - Notice how second row stays alinged to first row? I want to achieve that.