I've made a character using a btRigidBody (btCapsuleShape) and it works fine. Then I needed to test if it was on the ground (or any other object) so I could allow it to walk and/or jump. I tried to use a btPairCachingGhostObject (btSphereShape) at the bottom of the capsule and detect when it collided with the world (see the image below)
So what is the best way to detect if the character is on the ground?
but unfortunately it works for walls too (pressing the space bar many times when touching a high wall allows huge jumps).Detecting if the character is on ground
-
- Posts: 9
- Joined: Tue Sep 08, 2015 6:40 pm
Detecting if the character is on ground
You do not have the required permissions to view the files attached to this post.
-
- Posts: 72
- Joined: Wed Feb 24, 2010 9:49 pm
Re: Detecting if the character is on ground
How about raycasting from the character towards the ground?
-
- Posts: 456
- Joined: Tue Dec 25, 2007 1:06 pm
Re: Detecting if the character is on ground
Your ghost object can show you all the contact points. You can filter them and apply some logic to detect when a point is at the bottom of your sphere.
Edit: you can probably solve the problem simply by using a sphere with a smaller radius, so that it touches only the bottom of the capsule.
Edit: you can probably solve the problem simply by using a sphere with a smaller radius, so that it touches only the bottom of the capsule.
-
- Posts: 9
- Joined: Tue Sep 08, 2015 6:40 pm
Re: Detecting if the character is on ground
Thank you both for your answers and sorry for the late response, I was busy and didn't have time to reply.
For anthrax11: I don't know if that would work, but I'll try it. If it turns out better than the other solution, I'll stick with yours.
For Flix: Immediately after writing that question I thought about filtering the points (Seriously, I'm not lying), but I didn't have the time to test it (English class at afternoon - BTW English isn't my main language). I also think I'm going to put the ghost sphere a little bit down (like 0.001) because sometimes the character just gets stuck in place (it thinks it's not on the ground). I assume that's because of floating-point precision issues.
Right now it's 22:00 where I live, so I can't test anything today. Tomorrow I have school until 15:30 and I will only come back home at 17:00 so I will probably be able to test it tomorrow night.
Sorry for the detailed description of my routine.
For anthrax11: I don't know if that would work, but I'll try it. If it turns out better than the other solution, I'll stick with yours.
For Flix: Immediately after writing that question I thought about filtering the points (Seriously, I'm not lying), but I didn't have the time to test it (English class at afternoon - BTW English isn't my main language). I also think I'm going to put the ghost sphere a little bit down (like 0.001) because sometimes the character just gets stuck in place (it thinks it's not on the ground). I assume that's because of floating-point precision issues.
Right now it's 22:00 where I live, so I can't test anything today. Tomorrow I have school until 15:30 and I will only come back home at 17:00 so I will probably be able to test it tomorrow night.
Sorry for the detailed description of my routine.
-
- Posts: 9
- Joined: Tue Sep 08, 2015 6:40 pm
Re: Detecting if the character is on ground
Thanks, it worked. I used this simple code to let me know only when the lowest quarter of the sphere (in the Y-axis) is colliding:Flix wrote:Your ghost object can show you all the contact points. You can filter them and apply some logic to detect when a point is at the bottom of your sphere.
Edit: you can probably solve the problem simply by using a sphere with a smaller radius, so that it touches only the bottom of the capsule.
Code: Select all
GhostPoint.getY() < (-Radius + Radius / 2.0f); // GhostPoint is in local coordinates and Radius is the radius of both the capsule and the ghost sphere
Also do you mean a ray in the center? I don't think that would work. I was just playing Bioshock.
Sorry for the late response.