#Ground detection on slopes

1 messages · Page 1 of 1 (latest)

grave marsh
#

I need a tip for ground detection. I used a trick I found in many tutorials online which is raycasting. My problem is that when my character walks down a slope the state is quickly alternating between being grounded and falling. I can increase the size of the raycast which fixes the problem, but then you can jump in the air... And with jump buffering its especially noticeable, anyone have any great tricks?

#

Code that I use:

ember harness
#

I guess you could make a separate ground check for jumping

rancid pier
#

When you jump, you add a time where it will be consider in the air.

ember harness
#

being 0.1m above floor still counts as grounded but you can only jump if youre touching the floor

grave marsh
#

I guess that would work but there's still a problem

#

when the player is on ground I handle the Y velocity (for sticking to the ground), so if you're detected too early you will kinda start floating in mid-air

rancid pier
#

I was suggesting more of:
bool IsGrounded => CheckIfOnGround && HasNotJumpRecently

grave marsh
#

Yeah I got that

ember harness
#

I suppose you could instead handle movement relatively to the angle of floor

grave marsh
#

it would take care of jumping too early

#

but not the float issue I described

ember harness
#

like if youre on a 30deg slope, you will jump at an angle of 30deg

grave marsh
#

I dont see how that would help at all besides being a cool mechanic

rancid pier
#

I do not understand what velocity has to do with Ground check.

ember harness
#

and if you move, your horizontal movement will also go at an angle

grave marsh
ember harness
#

uhh Id illustrate it but Im on phone right now

grave marsh
#

When my character moves down slopes normally he would keep fall rather than walk down the slope

#

and when walking up it would create a bounce if you stopped

#

to fix that I added this code

#

but now if you're grounded too early it will cause the y to be set to 0 and you get stuck in air

rancid pier
#

Normally, you snap your character on the ground directly.

#

If it is like 0.1m over it.

#

You do not modify velocity.

grave marsh
#

wouldnt that be noticeable, and by snap you mean set the y coordinate directly?

rancid pier
#

Yes

grave marsh
#

hmm

rancid pier
#

And no, you would not notice a small snap

grave marsh
#

and worst case some smoothing could be added

rancid pier
#

True

grave marsh
#

I guess I will try it out, thank you

#

Wow

#

it worked really well

#

thank you guys 👍

grave marsh
#

actually

#

upon further testing its far from a perfect solution