- Home /
other object's position?
Hello. How can I get the position of another object (rather than always using a specific vector 3)?
Answer by Peter G · Dec 23, 2010 at 03:57 AM
I don't understand what you mean. Position in Unity is stored as a Vector3 so you must use a Vector3 somehow. There are plenty of ways to get the position. The easiest and probably best would be simply.
var somePos : Vector3 = otherObject.transform.position
- or if you don't want to explicitly declare a variable (Vector3 is a value type so there is no worry about memory allocation) then you could also do:
FireLaserAtPos(otherObject.transform.position);
- If you wanted to get fancy then you could get the objects bounds then go to the center of that.
var centerOfObject : Vector3 = someObject.renderer.bounds.center;
That's what I thought, but didn't want to be wrong, haha.
Sorry to be unclear. I meant not having to always use the same position (like 100,0, 25) and would ins$$anonymous$$d just have to select another object (so if that object moved, the position in the script would change to reflect that).
Your answer
![](https://koobas.hobune.stream/wayback/20220613092214im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Object not moving,Object not moving in any direction 1 Answer
Checking for object in position 1 Answer
Position an array of objects randomly 1 Answer
Object position question... 0 Answers