In making a fairly simple platformer type game, I have (once again) come up against the bane of my existence: ground detection. I’ve been thinking about simple solutions to this for a while, and done some searches, but nothing quite fits the bill.
When I refer to actors, I mean the player and AI driven characters with the potential for ground detection, rather than an object with the ‘actor’ button toggled.
The problem: I want a method of ground detection that is:
-simple to use for many different actors
-hopefully doesn’t involve a million objects such as empties that shoot rays
-has a minimal rate of failure
Solution 1- a ray sensor.
This is one of the simplest solutions, and one of the most promising, but it’s inherently flawed.
the good- simple, easy setup that can be implemented for ANY actor in almost no time
the bad- if a slope is too steep, or the actor is hanging over an edge, this method is helpless. Making the ray longer will help the slope issue, but then it’ll detect the ground when too far away.
Solution 2- separate ground- either splitting the ground into another object and giving it a property to be detected by a collision sensor, or assigning one texture to all ground faces and using a touch sensor. This is the most stable under controlled conditions, but also has some big holes.
The good- all the actors need is a simple collision or touch sensor, so implementing it there is easy. This method will not fail if the ground is immobile and horizontal.
The bad- if the ground rotates and/or is dynamic, as is common in platformers (box stacking, etc.) this solution is helpless. A box, which can have any given face up, cannot change which face has which texture according to it’s orientation so either the actors will detect any side of the box as the ground (eg the player could jump if falling and it’s side touches a box) or the box would have to be undetectable by this method.
Solution 3- lots of rays- For a little while I was using 8 empties each with a ray sensor in a circle at the player’s base to ensure detection. This method is the most capable in terms of failing, but also seems like way too much overkill.
The good- can function in almost any situation without problems.
The bad- along with it being irritating to have to set this up for every actor capable of jumping or any other activity requiring ground detection, the amount of objects resulting could actually impact performance pretty badly if there were enough actors in the area. This is also more irritating to slip into a control script.
There are also a number of things which, while they aren’t solutions alone, might be used as a fallback or alongside something else to compensate for their issues.
Z speed- there are 2 times when an object has z speed near 0- when on the ground and when at the peak of a jump.
Problems: obviously, the peak of a jump, but also when the actor is moving up or down a hill, it’ll return that it’s in the air.
getReactionForce- during one of my searches, I ran into someone using this for ground detection. In theory, it should do exactly what I want, but for that person it was spaztic, and personally I’ve never seen getReactionForce return anything but [0.0,0.0,0.0], regardless of whether I have rigid body on or off, whether it’s bouncing around like crazy, in free fall, or sitting still.
So now we get to the question (finally)
-how do you suggest I do ground detection?
or, if you don’t have a complete solution, feel free to suggest amendments to my list (I’ll update it as often as possible)
hoo, that was a lot of writing, I hope I wasn’t TOO long winded… ^^
 #2 amended