I can't seem to get this entity I scripted to function only on the ground and not when it is in air. I tried to create a tracer and use the "OnGround()" code, but it is all to confusing. What I'm asking for is if there is any code that will prevent my function from activating in air. Here is my original code, but I realized if I used a tracer, it would only function on the ground. I want the entity to function on any surface whether it is a prop, entity, or just the ground. I only want the entity not to function in the air.
[CODE]function ENT:Think()
local trace = { start = self:LocalToWorld(self:OBBMaxs()), endpos = self:LocalToWorld(self:OBBMins())}
local trace1 = util.TraceEntity( trace, ent )
if ( trace1.HitWorld ) then
local Roll = self.Entity:GetAngles().roll
if Roll < 90 && Roll > -90 then
self:AttemptJump()
else
self:AttemptFix()
end
end
end[/CODE]
if (trace1.Hit)
You might prefer a hull trace
(Anyway, I don't know if hulltraces will make the entity seem on the ground even if it's just slightly above it)
Edit: I did some debugging (Using util.TraceEntityHul and util.TraceEntity --- No Difference)
Test 1: Slightly above ground
Results: The script says the trace hit the ground, despite the two debug spheres saying it's rather impossible (They mark endpos and start of the trace)
[url]http://steamcommunity.com/sharedfiles/filedetails/?id=153040980[/url]
TraceResult:
[CODE]HitBox = 0
HitNonWorld = false
HitGroup = 0
HitPos = 672.501648 -8.418074 -12262.034180
FractionLeftSolid = 0
StartSolid = false
Hit = true
HitWorld = true
SurfaceProps = 30
Normal = -0.261215 -0.560117 -0.786152
HitSky = false
MatType = 67
PhysicsBone = 0
HitTexture = maps/gm_flatgrass/concrete/concretefloor028a_0_96_-12032
HitNormal = 0.000000 0.000000 1.000000
Entity = Entity [0][worldspawn]
Fraction = 0.71682417392731
StartPos = 684.858582 18.078640 -12224.844727
HitNoDraw = false[/CODE]
Test 2: Touching the ground
Results: The trace worked as expected, spheres also confirm this should work well.
[url]http://steamcommunity.com/sharedfiles/filedetails/?id=153041053[/url]
TraceResult:
[CODE]HitBox = 0
HitNonWorld = false
HitGroup = 0
HitPos = 688.793640 79.149902 -12262.034180
FractionLeftSolid = 0
StartSolid = false
Hit = true
HitWorld = true
SurfaceProps = 30
Normal = -0.250174 -0.564098 -0.786897
HitSky = false
MatType = 67
PhysicsBone = 0
HitTexture = maps/gm_flatgrass/concrete/concretefloor028a_0_96_-12032
HitNormal = 0.000000 0.000000 1.000000
Entity = Entity [0][worldspawn]
Fraction = 0.50419360399246
StartPos = 697.117737 97.919296 -12235.851563
HitNoDraw = false[/CODE]
Test 3: Way above ground
Result: Trace didn't hit
[url]http://steamcommunity.com/sharedfiles/filedetails/?id=153041144[/url]
TraceResult:
[CODE]HitBox = 0
HitNonWorld = false
HitGroup = 0
HitPos = 610.680603 210.966263 -12243.813477
FractionLeftSolid = 0
StartSolid = false
Hit = false
HitWorld = false
SurfaceProps = 0
HitSky = false
Normal = -0.235728 -0.570286 -0.786897
PhysicsBone = 0
HitTexture = **empty**
HitNormal = 0.000000 0.000000 0.000000
Entity = [NULL Entity]
Fraction = 1
StartPos = 626.237000 248.601166 -12191.883789
HitNoDraw = false[/CODE]
[QUOTE=~Razor~;41043906]if (trace1.Hit)
You might prefer a hull trace
(Anyway, I don't know if hulltraces will make the entity seem on the ground even if it's just slightly above it)
Edit: I did some debugging (Using util.TraceEntityHul and util.TraceEntity --- No Difference)
Test 1: Slightly above ground
Results: The script says the trace hit the ground, despite the two debug spheres saying it's rather impossible (They mark endpos and start of the trace)
[url]http://steamcommunity.com/sharedfiles/filedetails/?id=153040980[/url]
TraceResult:
[CODE]HitBox = 0
HitNonWorld = false
HitGroup = 0
HitPos = 672.501648 -8.418074 -12262.034180
FractionLeftSolid = 0
StartSolid = false
Hit = true
HitWorld = true
SurfaceProps = 30
Normal = -0.261215 -0.560117 -0.786152
HitSky = false
MatType = 67
PhysicsBone = 0
HitTexture = maps/gm_flatgrass/concrete/concretefloor028a_0_96_-12032
HitNormal = 0.000000 0.000000 1.000000
Entity = Entity [0][worldspawn]
Fraction = 0.71682417392731
StartPos = 684.858582 18.078640 -12224.844727
HitNoDraw = false[/CODE]
Test 2: Touching the ground
Results: The trace worked as expected, spheres also confirm this should work well.
[url]http://steamcommunity.com/sharedfiles/filedetails/?id=153041053[/url]
TraceResult:
[CODE]HitBox = 0
HitNonWorld = false
HitGroup = 0
HitPos = 688.793640 79.149902 -12262.034180
FractionLeftSolid = 0
StartSolid = false
Hit = true
HitWorld = true
SurfaceProps = 30
Normal = -0.250174 -0.564098 -0.786897
HitSky = false
MatType = 67
PhysicsBone = 0
HitTexture = maps/gm_flatgrass/concrete/concretefloor028a_0_96_-12032
HitNormal = 0.000000 0.000000 1.000000
Entity = Entity [0][worldspawn]
Fraction = 0.50419360399246
StartPos = 697.117737 97.919296 -12235.851563
HitNoDraw = false[/CODE]
Test 3: Way above ground
Result: Trace didn't hit
[url]http://steamcommunity.com/sharedfiles/filedetails/?id=153041144[/url]
TraceResult:
[CODE]HitBox = 0
HitNonWorld = false
HitGroup = 0
HitPos = 610.680603 210.966263 -12243.813477
FractionLeftSolid = 0
StartSolid = false
Hit = false
HitWorld = false
SurfaceProps = 0
HitSky = false
Normal = -0.235728 -0.570286 -0.786897
PhysicsBone = 0
HitTexture = **empty**
HitNormal = 0.000000 0.000000 0.000000
Entity = [NULL Entity]
Fraction = 1
StartPos = 626.237000 248.601166 -12191.883789
HitNoDraw = false[/CODE][/QUOTE]
The entity still functions in air if I use a trace hull.
[CODE]function ENT:Think()
local trace = { start = self:LocalToWorld(self:OBBMaxs()), endpos = self:LocalToWorld(self:OBBMins())}
local trace1 = util.TraceHull( trace )
if (trace1.Hit) then
local Roll = self.Entity:GetAngles().roll
if Roll < 90 && Roll > -90 then
self:AttemptJump()
else
self:AttemptFix()
end
end
end[/CODE]