Droping An Entity To The Ground

I Am working on a system of Entity’s that spawn you guessed it, More Entity’s. Only problem is if its on a hill it spawns another one in the air.
Ive tried using Entity:DropToFloor( ) but i don’t know how to set a system with that up.
When would i put Entity:DropToFloor( ) into the spawning process of an entity?

Well, after you spawn it. When you’ve done your spawning process( moving and rotating ), fire that method and it should work.

Wow that’s odd i had it on a timer for 0.1 second and it wouldn’t drop down, i changed it to 1 second after and now it does. but it does not when its over water. il keep messing around with it.
does this method also work when its going up hill ?

Still having problems with my entity’s, some times they drop some times they don’t.
I’m going to start reading up on traces to see if i can trace where the ground is below the entity and set its position to there.

You could be doing something to the entity after you spawn it. Even after the timer elapses.

This is what I’m working with.
[lua]

function ENT:Initialize()
self.Entity:SetModel(“models/models/tree.mdl”)
self.Entity:SetSolid( SOLID_VPHYSICS )
self.Entity:SetColor( 255, 255, 255, 255 )
timer.Create( “deleteme”…self.Entity:EntIndex(),0.1, 1, function()
if #ents.FindByModel(“models/models/tree.mdl”) >= 1000 then
self.Entity:Remove()
end
end)
timer.Create( “deletemeto”…self.Entity:EntIndex(),1.5, 1, function()
if #ents.FindInSphere( self.Entity:GetPos(), 200) > 1 then
self.Entity:Remove()
end
end)
timer.Create( “deletemewater”…self.Entity:EntIndex(),1.5, 1, function()
if self.Entity:WaterLevel() > 0 then
self.Entity:Remove()
end
end)
timer.Create( “timerder”…self.Entity:EntIndex(),1, 1, function()
self.Entity:DropToFloor()
end)
[/lua]
Is this where droptofloor should be? this is all after i have spawned it, but it doesn’t work

When you used timer.Create, self.Entity does not become defined.

Try:

[lua]
timer.Simple(1,function()
self.Entity:DropToFloor()
end,self,self) // Two selfs just in case
[/lua]

I’m currently working on making a tracer for the entity that will trace downwards to the ground and set the entity’s position.
only problem is its not working like always :/.
This is what i have:
[lua]
timer.Create( “tracedown”…self.Entity:EntIndex(),0.5, 1, function()
local pos = self.Entity:GetPos()
local ang = Angle( 90, 0, 0 )
local tracedata = {}
tracedata.start = pos
tracedata.endpos = pos+(ang*1000)
local trace = util.TraceLine(tracedata)
if trace.HitWorld then
MsgAll(" I FOUND THE WORLD !!!")
self.Entity:SetPos(trace.HitNormal)
else
MsgAll(" i didn’t find the world")
end
end)
[/lua]
It keeps saying " i didn’s find the world"
Any ideas on what could be wrong ?

The trace is probably hitting the entity. Add “tracedata.filter = self.Entity” to counter this.
By the way, I have a similar problem with a gamemode I’m making. My entity spawning code uses a trace to put them on the ground, but sometimes they just float in the air anyway.

Thanks! with that bit in there it lead me on the right track and after some fine tuning it works great here is the final code if anyone wants it:
[lua]
imer.Create( “tracedown”…self.Entity:EntIndex(),0.5, 1, function()
local pos = self.Entity:GetPos()
local tracedata = {}
tracedata.start = pos
tracedata.endpos = pos- Vector( 0, 0, 1000)
tracedata.filter = self.Entity
local trace = util.TraceLine(tracedata)
if trace.HitWorld then
self.Entity:SetPos(trace.HitPos)
else
end
end)
[/lua]