- Home /
Get all Game Objects near point
Hello, Im sorry if this has been asked but ive searched and cant find a thing.
So, I was wondering how to get all objects near a point like the title says.
I would Prefer NOT to use raycasts because my object may have a different Y cord.
Thanks, I use Unity Script
depends on the type of object ur using, was thinking if its a player or any other moving object, dunno how efficient it is but u could create a sphere collider around the object u want to count game objects and using OnTriggerEnter function, everytime u hit a tagged object or something u do count + 1, and count - 1 on OnTriggerExit
Ok, all i wanted to know is if there was some simple function like, GameObjectsNearPoint ect. idk
But there is not i guess. Thanks for your answers.
Answer by cdrandin · Feb 11, 2013 at 01:05 AM
The way I see this is like there is some gravitational pull at some place, i.e. could be some super villain just to paint a nice picture. Now this spell would move all nearby objects towards the origin of the pull. You will need to do a lot of math to get the objects to move towards the center if you want the objects to move based on their current rotation or you can simplify it by having the game objects LookAt
the origin of the pull which causes them to turn around with the Z axis pointing towards the origin, then just add a force to them and they will all move uniformly.
To get some cool stuff happening you would need rigidbody and customize each objects mass, and resistance, but if you just want a simple pull then just make your own move to center function.
Thats not even close to what i want, but thanks for the answer.
Ok now because of your previous post I now understand what you are talking about. Check out:
http://docs.unity3d.com/Documentation/ScriptReference/Physics.SphereCast.html
http://docs.unity3d.com/Documentation/ScriptReference/Physics.SphereCastAll.html
Sorry for the confusion.
SphereCast is the wrong answer - sphere cast is for finding if there are objects within a capsule shape (the documentation says to think of it like a thick linecast). The correct answer is Physics.OverlapSphere.
Also, the question was perfectly clear.
Answer by alibatiste · Dec 02, 2013 at 09:42 AM
I think this function solve your problem: http://docs.unity3d.com/Documentation/ScriptReference/Physics.OverlapSphere.html