How can I check if an object is on the ground?
I have a cube.
What I do right now is cast a ray from cube's center to ground and if the distance is bigger than half the cube's size, it is set as in air. The problem is that if the cube is on an angular surface, it gets marked as being in air because the distance from cube's center to ground became bigger.
What's a good way to check if it's on the ground even on angular surface?
You could get the collision data and get the position of the collision and the normal and then if the rotation of the normal is less than some certain value you set then you set your canJump boolean to true.
(psuedocode-ish)
maybe: use a child cube, about a quarter of the height of the parent (so it doesn't collide too high up), with a length x width error-margin you prefer around the outside, that looks for collisions. When it's in collision with an object, you're (probably) on the ground.
Edit: oh, but make sure the bottom of the child cube is aligned with the bottom of the parent cube and offset downward by the error-margin.