In order to compute various mechanical behaviours of a character, such as jumping and walking, it is necessary to know whether a Part is "on the ground".
Given an arbitrary physically simulated cuboid, how do you know when there is sufficient substance beneath it on which to rest itself?
If you don't understand what I mean, think of this related question "How do you know that a Part is or is not falling?". You might give a trivial answer, like "when the Y velocity is less than 0", and I would reply "I do not count sliding down a slope as falling".
I have experimented with two techniques, both of which are approximations host to various disadvantages:
Technique #1
Measure acceleration frame-by-frame and conclude that there is no ground beneath if the vertical acceleration is within N% of gravitational acceleration. Using a value of 15% was derived empirically and should represent a good upper bound.
Take "root" to be the physical Part in question:
prevy = root.Velocity.Y
t = tick()
coroutine.wrap(function()
while wait() do
local tempy = root.Velocity.Y
local deltat = tick() - t
local dydt = (tempy - prevy)/deltat --rate of change of velocity, i.e. acceleration
if math.abs(1+dydt/g) < 0.15 then
ground = false
else
ground = true
end)()
This technique is not always reliable with smaller upper bounds, and the greater the upper bound on the error %, the more unreliable other behaviour (such as walking down a steep slope) will be.
Technique #2
If any of a number of downwards rays parallel with the Y-axis comes into contact with something, conclude that there is ground beneath. I will not post the implementation of this technique, as it is computationally straightforward and intuitive.
The problem with this is that many rays are needed to be cast continually because only a fraction of the Part in question may be resting on a surface. Suppose that the smallest surface size of an ambient detail is 1 stud^2, how many rays need to be cast from a Part with a 4 st^2 bottom surface to guarantee that the 1 st^2 surface that it may be resting on is detected?
How do you suggest improving the above techniques, and what other approaches can you think of?
Thank you for your time!

7 comments
Thanks for taking the time to respond, Adark. I'm afraid I don't understand your proposed solution, though. How does placing a Part at the end point of the first ray cast (from the center of mass) achieve anything? Surely the placement of that first part is subject to the exact same problems as using one ray for the whole detection process in the first place. I may just be misunderstanding what yo
..what you wrote. Perhaps you could elaborate on this? Thanks.
You place the part AT the center of mass, and then do a single raycast FROM it, straight down. If the CoM is balanced, so is the entire model, if you just want basic physics.
However, that will allow it to fall through thin cracks (which is symptomatic of not solving the problem he wants)
A solution I use (sort of) for my Portal game is to "expand" all parts by the size of the player. This is the behavior requested. Expanding by less would get a mix which might be optimal.
I should have clarified that the rotation of the Part is locked in all but the Y-axis, so if any part of the surface is on ground then the whole block is stable, so CoM tests are unnecessary. As a side note, I don't understand why you say to place a Part there and update its position, rather than just keeping/updating a Vector3 of the CoM?
@BlueTaslem I don't understand your solution, either, I'm afraid! What do you mean by "expand" and how does this affect detecting ground?