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?
#Ground detection on slopes
1 messages · Page 1 of 1 (latest)
I guess you could make a separate ground check for jumping
When you jump, you add a time where it will be consider in the air.
being 0.1m above floor still counts as grounded but you can only jump if youre touching the floor
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
I was suggesting more of:
bool IsGrounded => CheckIfOnGround && HasNotJumpRecently
Yeah I got that
I suppose you could instead handle movement relatively to the angle of floor
like if youre on a 30deg slope, you will jump at an angle of 30deg
I dont see how that would help at all besides being a cool mechanic
I do not understand what velocity has to do with Ground check.
and if you move, your horizontal movement will also go at an angle
Wait Ill explain
uhh Id illustrate it but Im on phone right now
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
Normally, you snap your character on the ground directly.
If it is like 0.1m over it.
You do not modify velocity.
wouldnt that be noticeable, and by snap you mean set the y coordinate directly?
Yes
hmm
And no, you would not notice a small snap
and worst case some smoothing could be added
True