Universal ground detection

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… ^^

[edit] #2 amended

There’s an easy way that works very well!

The “Touch” Sensor…Give a material to your floor ( ex:floor)
Add a touch sensor to your object/character, put “floor” in the text field, and link it to an Actuator that will trigger whatever you want
Now, each time the character “leaves” the floor it’ll send a pulse

that would fall under solution 2 in terms of pluses and minuses (slightly better object counts, actually, but still almost the same) I’ll change #2’s write-up.

touch is just a fancy collision I think.

hey captain oblivion, in our AI tutorials, p00f wants to cover “failsafe” things.

when he does a terrain , he adds another mesh under the terrain incase the player should fall through the floor. the player hits the sub surface mesh, under the terrain and gets a +1 global Z when he collides with it. This will shoot him up out of the dirt.

p00f also says he does this in walls if he is having problems with the objects being shot through them.

maby your script can quickly look at the terrrain, and make a low poly “safety net” under the terrain when the game engine is first run?
either that, or the script looks for the lowest point in the terrain, and makes plane under the mesh to denote a “no fall zone”

I have a feeling this would cause some major lag in the games, but p00f swears by it, so we are going to try it later on.

this is a great effort Captain Oblivion, good luck on your quest :smiley:

Touch is just an obsolete version of Collision. It’s left in for backward-compatibility.

I find that a double solution works the best for me: use -Z rays that detect the objects with property “ground”. Using a ray prevents the character from walljumping. Of course, you’ll still get hanging issues, but maybe you could implement a collision sensor as a counter to that. And if a character rotates to match the slope, then there will be no hanging on slopes, just edges.

Ah! “Solution 2”?!..
Sorry I haven’t read entirely your post!?
Lack of “method”…that’s why I’m such a looser!