I want to check when my player(a Sphere shape and CharacterControl) lands during a fall. So I created a CollisionListener to check when the player collides with something and since the onGround() method only works if the player is jumping I decided to use the linear velocity to know if the player is falling.
The problem is that sometimes when I get the velocity on a fall collision the Y is zero, I suppose this is because I’m getting the velocity when the player already landed.
This happens when the fall distance is: 1(this one is not a problem) 3 4 6 10 units
I tried different things like:
Increase the CollisionShapeMargin
Modify the physic step and fall velocity
But those only mitigate a little the problem and have some drawbacks.
I also thought in using raycast in the update loop or add a additional CollisionShape at the bottom of the character or just use the update loop to store the last linear velocity.
On my current project, I use a GhostControl with Box shape below the player spatial (what happening when hitting an object from the side while falling?) and handle the whole thing in the players update loop. When the Box doesn’t collide and the vertical velocity is bigger than a value (GhostControl uses only AABB), it switches to the fall state; when it is in the fall state, the box collides and the velocity is 0, it switches to the landing state.
onGround() is intended to work even when the player hasn’t jumped.
I made changes in Minie version 5.0 that might be related to the issue you’re seeing. How is onGround() failing? Is it returning false when the character is on the ground? Or is it returning true when the character is airborne?
The biggest issue with CharacterControl is that crucial parts are hard-coded in C++ and are difficult to modify without breaking things. Perhaps you should consider switching to BetterCharacterControl or writing your own custom control based on BetterCharacterControl.
Hello @sgold, onGround() returns true when the character is airborne, works fine when the character jumps, but when, for example, it walks off a platform only returns true.
This also affected my jump logic since I only wanted it to be able to jump when is on ground but if it walks off a platform it can jump midair. But then I though:
Hmmm, that’s a nice feature to have.
So I let it be.
Anyway, thanks for the suggestion, I will try BetterCharacterControl.
If you need help reproducing the issue just tell me.