Collision woes - help?

Hey all - still having some collision detection issues with the ground. Using 3dPlatformer as a model and trying to debug to the console…not able to figure this one out.

I have this function:

function OnGround()
     {
     return (collisionFlags == CollisionFlags.CollidedBelow != 0);
     }

And then later, a movement function (which works fine except when I make it conditionally dependent on the OnGround function…)

function Update()
{
if (OnGround())
{
Move();
}
}

Just to test this, wrote this debug function:

if (collisionFlags == CollisionFlags.CollidedBelow != 0)
     {
     print("There is a collision below you.");
     }
else
     {
     print("There is NO collision below you.");
     }

Sure enough, when I am very high up from the ground, it says there IS something below my character…even when i’ve moved out to where there is no Terrain anywhere under my character’s feet at all! Any thoughts on how to remedy this? Thanks!

UPDATE
I tried this as well in the update function:

if (controller.isGrounded)
     {
     print("I am grounded!");
     }
else
     {
     print("Nope, I am NOT grounded");
     }

And even when my character is on the ground, this returns “Nope, I am NOT grounded”. I can not figure out why. Any thoughts as to a solution? I can’t get my fall/land scripts to work without this! Thanks.

Not sure if I’m missing something here, but the appropriate CollisionFlags value seems to be called “Below”, in fact I can’t see a “CollidedBelow” in the docs at all. Are you getting error messages when this is compiling?

Also, have you got a collider on the terrain?

Was this changed since Unity 1.x perhaps? The FPSWalker script (which hasn’t changed in years) uses CollidedBelow without any problems. CollidedAbove etc. also still work.

–Eric

Yeah, it IS a strange one…I still can’t explain it, but I did make a fix -

It seems that when I set Vector3.zero, it does NOT recognize a collision.

However, when I set Vector3(0,-1,0), it does.

I’ve tried resizing the collider both larger and smaller…same result. Soooo…i just changed all my y coordinates to -1 instead of 0, and viola…it seems to work just as it should. Strange. My terrain is definitely at 0, btw.