Position Script Question

Hello just a quick and dumb question

How to i change the Position from a child Object to the Position of the Parent Object.

What i want to do : is when Child reaches 0 HP to change Position to the Parents Position.

Or to a Set Game Object on the Screen thats not the parent >.>

// sets child object to the parent's position
childObject.transform.localPosition = Vector3.zero;

or

// sets child object to the parent's position
childObject.transform.position = childObject.transform.parent.position;

or

// sets child object to another object's world position
childObject.transform.position = otherObject.transform.position;

Thanks will give it a try

quick question for another App.

Same situation but i need to make an Offset for X and Y positions, i have an idea but i want to be sure.

If you want to set the child to an offset, you can set the local position equal to that offset.

1 Like

To expand, localPosition is the position of the object relative to its parent (or just the world coordinates if it doesn’t have a parent). In other words, it’s an offset from transform.parent.position.