- Home /
CapsuleCast gives backwards normal when touching collider at start position.
I am having some problems with CapsuleCastAll. I am trying to solve character collisions using it. So far it is working fine, but the one problem i have that i cannot solve is following:
If i cast a capsule from a to b, and if the capsule at a is exactly touching a collider, the hit will be on the inside of that collider. Following picture illustrates it, the vertical black line is the collider.
The fact that it hits at all is weird, since the capsule is going in the opposite direction and the colliders ar not overlapping, but not a big problem because i can just discard all hits for which the angle between the hit normal and the cast direction is smaller than 90. However, this becomes problematic when the normal is inverted, because i have no way of knowing wether or not it will be inverted, so i can't filter those hits out. This situation is very common in my game, because whenever a character is stopped by a collision, it will be exactly touching a wall.
Hence what i am asking is: is there a way to avoid getting these problematic hits, or is there a way to recognize them so they can be ignored?
Edit: i looked some more into the issue, specifically i read the documentation on CapsuleCastAll. It says that for casts starting inside of a collider, that hit will have its distance be 0, its normal be the opposite of the movement, and its point be Vector3.zero. I checked, and this seems to be what is causing me problem. However, even though i now know the source, i have not come up with a fix yet. This is because i simply have no way of differentiating between hits going away from a wall or towards the wall when my collider is exactly touching it, since i apparently don't have the normal of the hit.