I'm asking because there are 2 distinct possibilities as to how RaycastHit2D.fraction works when the hit value is returned via a Physics2D.CircleCast that begins with the centre of the CircleCast outside of the collider, but with the radius of the circle intersecting with the collider: Either the hit value returns a fraction of 0 as the CircleCast traveled no distance before returning a hit, or the hit value returns a fraction equal to the distance between the circle's centre and hit point divided by the max distance.

I wanted to ask this here instead of experimenting as I tried researching about this myself, but found that no one has asked about how fraction values work with CircleCasts, so I want to make it easier for the next person (and myself).

Does it return 0, the distance between the centre and hit point divided by the max distance, or something else entirely?

Memorie's user avatar

I didn't test this either but from reading the API I would claim both distance (and thereby fraction which is mainly just distance / maxDistance) should be 0.

Neither distance nor fraction care about the radius immediately just indirectly:

In general the distance for a CircleCast does NOT refer to the distance between the circle center and the hit point at all but rather between the center and the RaycastHit2D.centroid which is basically the virtual center of the circle shape when it finally hits something (for line and raycast this equals the hit point instead). So it basically translates to

How far did the circle have to travel before it intersected with the target?

So if as in your setup the circle radius already happens to be large enough for the circle to intersect with something then the answer would be

It didn't have to travel at all!

So distance would be 0 => fraction would be 0 as well.

derHugo's user avatar

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.