Alternative to IsOnGround?

Well, I’m back again with an extremely simple problem, as usual.
The title says it, and there is an example below.

concommand.Add("ongroundtest", function()
for k, v in pairs( ents.GetAll() ) do
if IsValid(v) then
print("Model:",v:GetModel(),"On Ground?",v:IsOnGround() )

If you spawn any prop (that is touching the ground) and type ‘ongroundtest’, IsOnGround will return false (at least for me). Maybe IsOnGround only returns true if the RootTransform is touching? Anyway, I need a solution for this extremely simple script that actually works with normal props (not players), and entities.

[editline]9th March 2015[/editline]

Sorry, I have a bad habit of making a whole thread for a really simple problem. I’ll post on from now on.

[editline]9th March 2015[/editline]

A hull trace is supposed to work okay, but if anyone has any alternatives, just post them here, I’ll mark this as solved tomorrow.

[editline]9th March 2015[/editline]

By the way, I screwed up quite a lot of traces in the past, so if anyone could give an example based on this, it’d be really helpful.



function is actually for entities, which are not handled by physics engine I think, test that by spawning npc befire using command. Instead of

v:GetModel() == nil

you can use


in the if statement(without the “not”) as you can probably set model of entity before actually spawning it.

I used traces to tell whether or not my SENT was touching the ground at a specific point:

        local frntleg = {
            start = self:LocalToWorld(Vector(0, 0, 0)),
            endpos = self:LocalToWorld(Vector(-0.6, 0, -3)),
            filter = self
        local trfrnt = util.TraceLine(frntleg)

if trfrnt.Hit then print ("on ground") end

Note you’ll have to set your own start and end positions. This means this will need to be model specific (I’m sure there’s a better way of doing this for a large variety of props, such as tracing a downwards trace with a start position of the entity’s actual model. There was a good tool for that somewhere but I forgot its name). You can also use the trace result to know what entity it’s hitting and whether or not it’s worldspawn if you care about that.
Also, if you’re planning on doing it this way, a good debug visualization solution would just be to draw the line:

render.DrawLine(start vector, end vector, Color(255, 255, 255), true)

a TraceHull and a TraceLine are going to be your only good alternatives

Use entity:OnGround()

Same problem. I can’t find a difference between this and the current :confused:

[editline]10th March 2015[/editline]

So… if the Entity:IsOnGround is for entities, what am I meant to use for props?

[editline]10th March 2015[/editline]

Great, the new Gmod update doesn’t even fix this problem -_-