Quantcast
Viewing latest article 8
Browse Latest Browse All 90

Answer by Matt-Downey

First something that might give you a little insight. Physics.SphereCast will return false if the imaginary sphere starts its "sweep" while already inside of an object. Basically, you can think of Physics.SphereCast as: if(!Physics.CheckSphere(transform.position,...)) //if the current position is not occupied { Physics.SphereCast(); //then cast the sphere as you would suspect } Looking at why they would both fail, knowing this, I would guess that what is happening, is that from Physics.SphereCast() the default RaycastHit information is being returned: normal = Vector3(0,0,0), distance = 0, etc. This would mean the next check is checking at the origin of your map Vector3(0,0,0) in world space and looking for a collision within whatever radius. Try removing any colliders from the position Vector3(0,0,0) in world space and see if the second statement returns true every single time. If so then that was why the second statement was failing. The fix for the first statement is relatively hard, I would suggest using a smaller radius for the spherecast (by at least 0.11). Furthermore: in edit (tab)-->project settings-->physics you can change the variable "min penetration for penalty" to a lower number like 0.01 or 0.005 (or lower although it is the law of diminishing returns) until the collisions are precise enough for your tastes, which should make everything work better. (If you do this, instead of subtracting 0.11 from the radius you can subtract 2*n + 0.01 instead.)

Viewing latest article 8
Browse Latest Browse All 90

Trending Articles