0
\$\begingroup\$

I have my "player" object moving around an arena type area, with miscellaneous objects scattered about. What I want to do is move the player near any of these objects, and on keypress I want to display a circular radius with the player in the center that will detect nearby objects (eventually being filtered by tag).

I realize there are many ways to accomplish this, but being relatively new to Unity I am trying to find a way that is intuitive to me. Looking at the documentation, Physics2D.CircleCastAll seems like it would fit my needs, but I am unable to test at this time (at work).

Provided CircleCastAll is what I do use, is there a way in the scene to display the circle that is being cast so that the player can visually see the radius? I know it returns a RayCastHit2D, so I can get the objects from that, but the player should have something visual to let them know if they are slightly out of range or not.

Any suggesions/tips are welcome. Thanks in advance!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Your rendered effect is going to be completely separated from the physics cast. The cast will tell you what is there, you will need to handle the drawing with a separate object. Decals are frequently used. \$\endgroup\$ Commented Dec 7, 2015 at 19:45

1 Answer 1

3
\$\begingroup\$

I think you are misunderstanding how CircleCastAll works. A good analogy to describe it is that CircleCastAll is throwing a frisbee of a certain radius over a distance and then returning all object that this frisbee hits. What I think you are looking for is a circle that emanates from the user and that does not move over a distance. The proper way to perform this action is with OverlapCircleAll. For this you would simply set the point of the circle to be your player's position and the radius to the radius of your desired circle.

Now onto the hard part. OverlapCircleAll and all other Physics functions in only return the Colliders of the things that were hit. They do not interact with visuals in any way. This you will need to do on your own. The easiest way I can think of to do this is to have an animated circle appear that is the same radius as your OverlapCircleAll appear at the same time as your OverlapCircleAll.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ This helped me out a lot. OverlapCircleAll makes way more sense then CircleCastAll for my needs, thanks for that help! \$\endgroup\$
    – Blankdud
    Commented Dec 8, 2015 at 13:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .