Creating a transition delay from isgrounded=true to not for improved control

Hello people. These 2 lines of code seem to control if the player controller is grounded. I want to add something that says if this code is not true for more than 0.2 seconds, then the player is not grounded essentially creating a delay. I want to do this because it would make the player walk normally on ground that is uneven and more importantly make it possible for players to be able to jump from the very edge of a platform. Maybe it could also be done if the ground is checked when the player’s rigidbody.velocity.y is lower than -1 or something?

The 2 lines of code that check ground:

DistanceToCheckGround = RB.velocity.y < 0 ? OriginDistance : 0.5f;

bool DownwardsRay = Physics.Raycast (transform.position + (Vector3.up * 0.1f)/* + (-Vector3.back * 0.3f)*/, Vector3.down/* + (-Vector3.back * 0.3f)*/, out Info, DistanceToCheckGround);

So this approach doesn’t work because velocity.y could be negative when grounded, think going down a slope for example.

The trick to walk on uneven surfaces and keep the player snapped to the ground is to apply a fake gravity when the player is grounded. You can pick a value proportional to your walk/run speed and multiply it by 2 to get your fake gravity force, by doing something like this, you always push your player against the topology and it always is stronger that your movement speed.

Don’t know if my explanation makes sense?

That sounds like a good idea but i don’t know if it will make air jumping possible. I guess a 0.2 sec delay transition from is grounded to not is the ideal way. Thanks anyway!

Anything happening when your player is airborne is not impacted by the fake gravity, as it is only applied when grounded. As soon as you leave the ground, you either jump or fall. If you jump, you could technically not use any gravity at all (when ascending) but this depends on how you want your jump mechanic to feel (arcade or physically accurate), when you fall you apply real gravity (-9.81m.s-2) if you want a physically accurate behavior, or again a custom value if you’re looking for a more “arcade” feeling.