Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  4. Build games and experiences that can load instantly and without install. Explore the Project Tiny Preview today!
    Dismiss Notice
  5. Nominations have been announced for this years Unity Awards. Celebrate the wonderful projects made by your peers this year and get voting! Vote here!
    Dismiss Notice
  6. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  7. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Physics2D.CircleCast radius and distance parameters

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

  1. Honkry

    Honkry

    Joined:
    Apr 7, 2013
    Posts:
    93
    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,530
    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).
     
  3. Honkry

    Honkry

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

    MelvMay

    Unity Technologies

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

    Honkry

    Joined:
    Apr 7, 2013
    Posts:
    93
    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,530
    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. Honkry

    Honkry

    Joined:
    Apr 7, 2013
    Posts:
    93
    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,530
    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. Honkry

    Honkry

    Joined:
    Apr 7, 2013
    Posts:
    93
    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,530
    Stamblew and dongrout like this.
  11. Honkry

    Honkry

    Joined:
    Apr 7, 2013
    Posts:
    93
    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,530
    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:
    15
    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 :)