- Home /
Putting objects inside an empty GameObject changes the original position.
So i'm new to unity, and i'm trying some things before going for a Tower Defense game.
I checked the LookAt function with a camera pointing a simple object(like cubes), and it works fine. I also tried with simple objects facing other simple objects.
Then, i make a "Enemy" which is composed by cubes and spheres, and a "Tower" which is made from cylinders and spheres. The tower is divided on two parts: base and top, and top part should face the Enemy.
Here is the "fail". When i use the LookAt function, if i move the Enemy, the tower starts doing an orbit-like move too, instead just facing the enemy. Then i try the same thing with a simple object facing the enemy, and it works, but i observe that the object looks to a point which is different to the actual position of the enemy. Like if enemy has a "real" position and a "fake" position.
I confirmed this by adding a sphere collider to enemy, and -what a surprise- it appears just at the point i mentioned.
Why this happens?
@$$anonymous$$usho: Don't forget to say what answer respond to your question.
Answer by meat5000 · Nov 20, 2013 at 11:07 PM
When you parent one object to another, the transform of the child becomes relative to the parent. The transform of the child in the inspector is local transform. A child object will also move with the parent.
In hierarchy, a gameobject dropped onto another gameobject becomes a child of that object.
Thanks, man! I cannot upvote, since i'm a newbie, but i wanted to do it! :D
When a object don't have parent, it show is world position. (In reality, is parent is the world)
In script, you are still able to access is World Position:
transform.position //Give world position
transform.localPosition //Give position relative to the parent
@meat5000: I would suggest to use the Community Answer feature, it allow other to edit your answer. Because I feel you answer the question, but wanted to add info. At first, I've created an new answers, but feel like it was s$$anonymous$$ling.
Your answer
Follow this Question
Related Questions
Trouble with positioning 2 Answers
get object with tag for LookAt(); 2 Answers
Change LookAt Face 1 Answer
View an array of the transform position/rotation of all game objects with a specified tag., 0 Answers