Physics2D.CircleCast radius and distance parameters

Hi,

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

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).

1 Like

Yes but when is that not the same?

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?

1 Like

Oh so radius is like the size of the circle distance is like an offset?

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).

2 Likes

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?

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.

1 Like

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())?

If the circle isn’t moving then you don’t need a cast but an overlap check:

Physics2D.OverlapCircle

Physics2D.OverlapCircleAll
Physics2D.OverlapCircleNonAlloc

You only have to provide the point (center of the circle) and the radius. The rest are optional.

7 Likes

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!

1 Like

No problem, glad I could help.

1 Like

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?

You can use 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!

Is there example code for Physics2D.CircleCast

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.

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!

1 Like