Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

Physics2D.CircleCast radius and distance parameters

Discussion in 'Physics' started by h0nka, Nov 5, 2015.

  1. h0nka

    h0nka

    Joined:
    Apr 7, 2013
    Posts:
    109
    Hi,

    Just a quick question: What the devil is the difference between the effects of the radius and distance parameters in the CircleCast?
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,409
    Have you read the documentation? Physics2D.CircleCast

    As it states, the radius is the radius of the circle. The distance is the distance to cast the circle over (away from the origin you specify).
     
    Content1of_akind likes this.
  3. h0nka

    h0nka

    Joined:
    Apr 7, 2013
    Posts:
    109
    Yes but when is that not the same?
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,409
    I don't follow what you mean.

    The origin is the start of the circle.
    The radius is the radius of the circle.
    The direction is the normalized direction to move the circle
    The distance is how far (along the direction) to move the circle

    So in other words, the cast is a circle of 'radius' moving from 'origin' to 'direction * distance'.

    This is what shape casts are. You define the shape, the origin, the direction and how far to cast the shape through space.

    Does that help?
     
    Stamblew likes this.
  5. h0nka

    h0nka

    Joined:
    Apr 7, 2013
    Posts:
    109
    Oh so radius is like the size of the circle distance is like an offset?
     
  6. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,409
    It's not an offset no.

    Casting means moving a shaping through space from one point to another catching collisions along the way. In this case it's a circle. Origin is the start point and the end-point is origin + (distances * direction).
     
    Stamblew likes this.
  7. h0nka

    h0nka

    Joined:
    Apr 7, 2013
    Posts:
    109
    Ok. So the radius would then determine the size of the circle before it 'expands'? If so, would anything within the radius not get caught by the cast then?
     
  8. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,409
    I think you're fundamentally misunderstanding something here. The circle doesn't expand. As I've said several times now, CircleCast finds things that intersect a circle of fixed radius that moves from one point to another. The radius does not change, the circle moves between two points you specify.
     

    Attached Files:

    Stamblew likes this.
  9. h0nka

    h0nka

    Joined:
    Apr 7, 2013
    Posts:
    109
    Oh damn! You're right. I fundamentally misunderstood the circle cast. I thought it worked like a radar blimp or like a ring in water from a water drop. Thanks for being patient. Can i use a circle cast to detect objects in a radius around an object? Or would another approach be more appropriate (like RaycastAll())?
     
  10. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,409
    Fabii555, ladismad, wlwl2 and 4 others like this.
  11. h0nka

    h0nka

    Joined:
    Apr 7, 2013
    Posts:
    109
    Aha! See that's what I was confusing the circle cast with. Don't know why I didn't think about the 'cast' bit. Thank you for helping me out!
     
    wlwl2 likes this.
  12. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,409
    No problem, glad I could help.
     
    Stamblew likes this.
  13. wsimm101

    wsimm101

    Joined:
    Jul 17, 2018
    Posts:
    1
    Seems I was fundamentally misunderstanding the circle cast also! Thanks for the help. I've spent all day bumping off walls, or not as the case may be. Is there any way to visualize the circle?
     
  14. merpheus

    merpheus

    Joined:
    Mar 5, 2013
    Posts:
    202
    You can use
    Code (CSharp):
    1.  Gizmos.DrawWireSphere
    or create an editor that derrives from SceneView and use Handles API to draw circle in SceneView. Sorry for late answer but I also misunderstood circle cast and thanks for correction guys!
     
  15. Content1of_akind

    Content1of_akind

    Joined:
    Dec 2, 2018
    Posts:
    12
    Is there example code for Physics2D.CircleCast
     
  16. s4shrish

    s4shrish

    Joined:
    Jul 6, 2017
    Posts:
    8
    Okayyy, so essentially it is like a physically thicker version of Raycast in 2d space.

    So for eg. useful in detecting like a kamehameha beam wave that touches multiple objects it is passing through.

    I confused it with Overlap circle and was wondering why the direction is a required parameter in the definition. I simply added a zero vector for direction and 0 distance, and used it like overlap circle. Seems like an inefficient way now.

    Thanks for the clarification guys.
     
  17. stealthyshiroean

    stealthyshiroean

    Joined:
    Jun 29, 2021
    Posts:
    6
    Just wanted to say that I also was misunderstanding what a CircleCast was. Not sure why since I understand that a normal Raycast shot out an invisible line...anyway, thanks for the patience because in the end it seems like it probably helped out loads of people, not just the OP. Also, that picture did loads to visualize what was going on!
     
    MelvMay likes this.