- Home /
How get object, if i know coordinates?
For example: Give Vector3(3,3,3) and i know exist object with coordinat's Vector3(3,3,3), need get this object. Two question: How get normal of Object?
Answer by StephanK · Oct 27, 2010 at 01:21 PM
If you need to get objects by position it would be a good idea to keep a list of relevant objects, to speed up the process. The brute force method would be this:
Vector3 position = new Vector3(3,3,3);
GameObject[] objs = GameObject.FindSceneObjectsOfType(typeof(GameObject));
GameObject myObject = null;
foreach (GameObject go in objs) {
if (go.transform.position == position) {
myObject = go;
break;
}
}
But this would be a rather slow solution. As I said you can improve it to only search the relevant objects of your scene.
An object doesn't have a normal. Only surfaces/polygons do. You can get an objects up, right and forward axis. So if you have a plane and know in which direction the planes normal is pointing you could use that.
Answer by · Oct 27, 2010 at 10:33 PM
As an alternative solution to what spree suggested, if the object has a collider, you could use Physics.OverlapSphere to return an array of the objects at that position.
Your answer

Follow this Question
Related Questions
Instantiate and destroy on given location 1 Answer
Moving an object along a prespecified trajectory according to coordinates from arrays 2 Answers
Problem with Camera.ScreenToWorldPoint 0 Answers
How to put Object in the perticular Location? 1 Answer
Objects in the same place with different coordinates 2 Answers