|
Basically I need to know what inner workings can make these checks false, even though everything I can see indicates they should be true. Details below: Trying to make a gameobject warp to a point, but it must check for a valid destination first. Step 1: Step 2: And that's all wonderful when it works, but it frequently fails in this scenario: None of the objects can move during the check. The checks are performed in one frame in FixedUpdate, and I've toyed with improving the physics solver quality and fixed timestep. Any advice as to why this can fail?
(comments are locked)
|
|
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: 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.)
(comments are locked)
|

Instead of using the word fail/succeeds, could you say, true/false. I think I know what you are saying, but my common sense is a lot worse than my programming.
I interpreted the first fail as the sphereCast returned false, and the second fail as the checkSphere returned true (therefore the position the player wanted to move to was occupied).