Search Unity

  1. Unity 2019.1 is now released.
    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:
    99
    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:
    1,646
    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:
    99
    Yes but when is that not the same?
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    1,646
    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:
    99
    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:
    1,646
    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:
    99
    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:
    1,646
    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:
    99
    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:
    1,646
  11. h0nka

    h0nka

    Joined:
    Apr 7, 2013
    Posts:
    99
    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!
     
  12. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    1,646
    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. m3rt32

    m3rt32

    Joined:
    Mar 5, 2013
    Posts:
    40
    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. hasanali45

    hasanali45

    Joined:
    Dec 11, 2018
    Posts:
    1
    you're fundamentally misunderstanding something here. The circle doesn't expand. Visit us, we have experienced teachers who can solve your questions. Thank you :)
     
  16. Content1of_akind

    Content1of_akind

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