- Home /
Identifying Objects around me
So, I want my box to be able to identify if it contacts an object within a certain radius, like this:
Is using something like circlecast from physics 2D the way or? Also, I prefer it to be 2D thing if using raycast is the solution, since my game is only 2d.
Do you mean some specific objects? $$anonymous$$g. objects tagged as "Enemy"?
Answer by Umresh · Jun 24, 2015 at 01:47 PM
Using Raycast you can cast ray in one direction. You have to use the collider and detect the colliding objects.
Answer by SomeGuy22 · Jun 24, 2015 at 03:39 PM
Or if you don't need collision data you could use Distance equations that check all possible objects within a certain distance. And since you calculate distance from that first cube, the distance you check becomes the radius of the circle.
Answer by Nerevar · Jun 24, 2015 at 11:49 AM
You can have a circle collider 2D on your object set to "trigger" then implement OnTriggerEnter or OnTriggerStay2D to detect object inside the radius, it should be working for your problem.
Edit : you can identify objects with their name, tags or many other ways.