I did a circle cast sort of like this: Physics2D.CircleCast(origin, radius, vector, vector.magnitude, mask)
And an OverlapCircle like this: OverlapCircleAll(origin + vector, radius, mask)
For some reason the overlap sometimes detects something that the circle cast doesn’t. This should never happen because the overlap is the last stage of the circle cast. Anything the overlap detects should also be picked up at the latter part of the circle cast.
I don’t understand how or why this happens. I need to use circle cast because it returns more info about the hit, but I can’t because it isn’t reliable.
Did you even read my post carefully? I understand perfectly fine how they work. I put the overlap at the last position that the circle cast will check. Therefore, if the overlap detects anything, the circle cast should also detect it at the last position.
The only difference (albeit it’s a big difference) between the two besides what they return is this:
The overlap checks one position.
The circle cast checks a start position, an end position, and all the positions in between.
Therefore, since my overlap is placed at the end position, it should also be covered by the cast.
CircleCast returns the first thing it hits along it’s trajectory, OverlapSphereAll returns all the things within the radius. In your cases where it’s not doing what you want is it hitting something before it gets to the end?
No, I am simply testing if they hit anything at all. Sometimes the overlap says it is overlapping something and the circle cast didn’t hit anything so nothing before either. I also made sure they used the same layer mask as well. As you can see in the code I provided they use the same variables.
EDIT: It’s worth noting that my game has a bug and I’ve figured out that the bug only occurs on the same frames that the overlap and cast functions disagree.
Yes, I did. Even if I hadn’t, I just stated they work differently, because your explanation was a bit unclear (to me, sorry for that) so my first guess was that you might have missed something.
So, it is really extremely noticable or is rather just a little inaccuracy?
Sorry for the attitude. And, yes it is noticeable. I think I may be using circle cast wrong, but I have checked and double checked the documentation reading the description of every parameter. I confirmed that it is causing a bug that needs to be fixed because the bug only happened on the frames that the overlap and cast disagreed.
Okay, no problem, i just wanna help.
I tested both and they work just fine, with one small exception.
First of all, my scenario was pretty much set up to reduce floating point imprecision as much as possbile, I set it up close to the origin and kept the positions and directional vectors rather small.
In order to visualize and analyze everything, I used Gizmos and Debug.Logs.
Using the CircleCast appears to work almost exact to me (failed to detect an object’s collider that was roughly 0.003f inside of the “end” of the CircleCast). That’s really acceptable in my opinion. Keep in mind there has to be done some math behind the scenes, for example, normalizing the direction (can already cause some inaccuracy) and then multiplying with the length to cast into this direction (another source for some more imprecision). In some cases that can all add up and give false positives.
Now as for the OverlapCircle, I still got a false positive when the collider was already roughly 0.01 out of range. It detected everything that was inside the circle + a bit more). That’s still acceptable, isn’t it? Unless you got a static scene and visualize the actual casts it wouldn’t be recognized at all. At least in my setup, unless I had observed the positions, I really had to zoom in quite a bit in order to see what’s wrong and what’s right.
Maybe you can share some more information about your scene, or drop a screenshot?
I increased my sprites from 100 pixels per unit (0.01f = 1 pixel) to 1 pixel per unit (1f = 1 pixel) to lessen the effects of floating point imprecision and that solved my issue. Thanks for your help!