- Home /
How should I check if the charactercontroller is grounded next in the next calculation?
I need to find out whether my charactercontroller is grounded or in the next calculation, but I have no idea how I should do that.
Answer by supernat · Dec 20, 2013 at 06:09 AM
If you mean you need to determine if the player will be underground in the next frame, you can use Extrapolation. You would take the character's current downward velocity (and acceleration) and the last frame time (or frame time average) and forward extrapolate the position of the character assuming the next frame will occur at the same interval. In other words, take the current position and add velocity deltaTime + accel deltaTime * deltaTime / 2. Then you can look at the bounds.extents property of the collider to determine if they go under ground. You can use Terrain.SampleHeight() if you are using the built-in terrain to get the terrain height at the player's location.
I'm having a little trouble understanding how I would use the extrapolation, perhaps you'll be able to give me a simpler solution if i explain my problem a little better,
so, my initial problem was that when my character was walking down slopes he didnt stick to them on the way down but bumped down them ins$$anonymous$$d, so my solution to that was that if the was walking on a slope he would get a -y speed according to how steep the slope is in order to stick him to the slope. that worked pretty well except for one flaw that is if I walk off that said slope into mid air the character gets that -y speed for 1 cycle of calculation resulting in what looks like a downward lag spike, if I could check whether the character is grounded in the next calculation I would be able to prevent the character from getting that -y speed before he actually goes airborne so he wont get a sudden downward spike.