mirror of
https://github.com/SpaxscE/LunasFlightSchool.git
synced 2025-03-04 03:13:27 -05:00
some ai fixes
This commit is contained in:
parent
0a37ed1244
commit
1f7ec350a7
@ -2,7 +2,7 @@
|
||||
simfphys = istable( simfphys ) and simfphys or {}
|
||||
simfphys.LFS = istable( simfphys.LFS ) and simfphys.LFS or {}
|
||||
|
||||
simfphys.LFS.VERSION = 318
|
||||
simfphys.LFS.VERSION = 319
|
||||
simfphys.LFS.VERSION_TYPE = ".GIT"
|
||||
|
||||
function simfphys.LFS.GetVersion()
|
||||
|
@ -1103,11 +1103,17 @@ end
|
||||
|
||||
function ENT:RunAI()
|
||||
local RangerLength = 15000
|
||||
local mySpeed = self:GetVelocity():Length()
|
||||
local MinDist = 600 + mySpeed * 2
|
||||
local StartPos = self:GetPos()
|
||||
|
||||
local TraceFilter = {self,self.wheel_L,self.wheel_R,self.wheel_C}
|
||||
local mySpeed = self:GetVelocity():Length()
|
||||
local myRadius = self:BoundingRadius()
|
||||
local myPos = self:GetPos()
|
||||
local myDir = self:GetForward()
|
||||
|
||||
local MinDist = 600 + mySpeed * 2
|
||||
|
||||
local StartPos = self:LocalToWorld( self:OBBCenter() )
|
||||
|
||||
local TraceFilter = self:GetCrosshairFilterEnts()
|
||||
|
||||
local FrontLeft = util.TraceLine( { start = StartPos, filter = TraceFilter, endpos = StartPos + self:LocalToWorldAngles( Angle(0,20,0) ):Forward() * RangerLength } )
|
||||
local FrontRight = util.TraceLine( { start = StartPos, filter = TraceFilter, endpos = StartPos + self:LocalToWorldAngles( Angle(0,-20,0) ):Forward() * RangerLength } )
|
||||
@ -1127,22 +1133,18 @@ function ENT:RunAI()
|
||||
local Down2 = util.TraceLine( { start = self:LocalToWorld( Vector(0,0,100) ), filter = TraceFilter, endpos = StartPos + Vector(0,0,-RangerLength) } )
|
||||
|
||||
local cAvoid = Vector(0,0,0)
|
||||
if istable( self.FoundPlanes ) then
|
||||
local myRadius = self:BoundingRadius()
|
||||
local myPos = self:GetPos()
|
||||
local myDir = self:GetForward()
|
||||
for _, v in pairs( self.FoundPlanes ) do
|
||||
if IsValid( v ) and v ~= self and v.LFS then
|
||||
local theirRadius = v:BoundingRadius()
|
||||
local Sub = (myPos - v:GetPos())
|
||||
local Dir = Sub:GetNormalized()
|
||||
local Dist = Sub:Length()
|
||||
|
||||
if Dist < (theirRadius + myRadius + 200) then
|
||||
if math.deg( math.acos( math.Clamp( myDir:Dot( -Dir ) ,-1,1) ) ) < 90 then
|
||||
cAvoid = cAvoid + Dir * (theirRadius + myRadius + 500)
|
||||
end
|
||||
end
|
||||
|
||||
for _, v in pairs( LVS:GetVehicles() ) do
|
||||
if v == self then continue end
|
||||
|
||||
local theirRadius = v:BoundingRadius()
|
||||
local Sub = (myPos - v:GetPos())
|
||||
local Dir = Sub:GetNormalized()
|
||||
local Dist = Sub:Length()
|
||||
|
||||
if Dist < (theirRadius + myRadius + 200) then
|
||||
if math.deg( math.acos( math.Clamp( myDir:Dot( -Dir ) ,-1,1) ) ) < 90 then
|
||||
cAvoid = cAvoid + Dir * (theirRadius + myRadius + 500)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -1164,6 +1166,8 @@ function ENT:RunAI()
|
||||
|
||||
local TargetPos = (FLp+FRp+FL2p+FR2p+FL3p+FR3p+FUp+FDp+Up+Dp) / 10
|
||||
|
||||
self._AIFireInput = false
|
||||
|
||||
local alt = (self:GetPos() - Down2.HitPos):Length()
|
||||
|
||||
if alt < MinDist then
|
||||
@ -1190,34 +1194,36 @@ function ENT:RunAI()
|
||||
if alt > mySpeed then
|
||||
local Target = self:AIGetTarget()
|
||||
if IsValid( Target ) then
|
||||
if self:AITargetInfront( Target, 65 ) then
|
||||
if self:AITargetInFront( Target, 65 ) then
|
||||
TargetPos = Target:GetPos() + cAvoid * 8 + Target:GetVelocity() * math.abs(math.cos( CurTime() * 150 ) ) * 3
|
||||
|
||||
|
||||
local Throttle = (self:GetPos() - TargetPos):Length() / 8000 * self:GetMaxRPM()
|
||||
self.TargetRPM = math.Clamp( Throttle,self:GetIdleRPM(),self:GetMaxRPM())
|
||||
|
||||
|
||||
local startpos = self:GetRotorPos()
|
||||
local tr = util.TraceHull( {
|
||||
start = startpos,
|
||||
endpos = (startpos + self:GetForward() * 50000),
|
||||
mins = Vector( -30, -30, -30 ),
|
||||
maxs = Vector( 30, 30, 30 ),
|
||||
mins = Vector( -50, -50, -50 ),
|
||||
maxs = Vector( 50, 50, 50 ),
|
||||
filter = TraceFilter
|
||||
} )
|
||||
|
||||
local CanShoot = (IsValid( tr.Entity ) and tr.Entity.LFS and tr.Entity.GetAITEAM) and (tr.Entity:GetAITEAM() ~= self:GetAITEAM() or tr.Entity:GetAITEAM() == 0) or true
|
||||
|
||||
local CanShoot = (IsValid( tr.Entity ) and tr.Entity.LVS and tr.Entity.GetAITEAM) and (tr.Entity:GetAITEAM() ~= self:GetAITEAM() or tr.Entity:GetAITEAM() == 0) or true
|
||||
|
||||
if CanShoot then
|
||||
if self:AITargetInfront( Target, 15 ) then
|
||||
self._AIFireInput = true
|
||||
|
||||
if self:AITargetInFront( Target, 15 ) then
|
||||
self:HandleWeapons( true )
|
||||
|
||||
if self:AITargetInfront( Target, 10 ) then
|
||||
if self:AITargetInFront( Target, 10 ) then
|
||||
self:HandleWeapons( true, true )
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
if alt > 6000 and self:AITargetInfront( Target, 90 ) then
|
||||
if alt > 6000 and self:AITargetInFront( Target, 90 ) then
|
||||
TargetPos = Target:GetPos()
|
||||
else
|
||||
TargetPos = TargetPos
|
||||
@ -1242,9 +1248,9 @@ function ENT:RunAI()
|
||||
|
||||
self.smTargetPos = self.smTargetPos and self.smTargetPos + (TargetPos - self.smTargetPos) * FrameTime() or self:GetPos()
|
||||
|
||||
local TargetAng = (self.smTargetPos - self:GetPos()):GetNormalized():Angle()
|
||||
self._lvsAITargetAng = (self.smTargetPos - self:GetPos()):GetNormalized():Angle()
|
||||
|
||||
return TargetAng
|
||||
return self._lvsAITargetAng
|
||||
end
|
||||
|
||||
function ENT:CreateAI()
|
||||
@ -1279,13 +1285,7 @@ function ENT:OnSkyCollide( data, PhysObj )
|
||||
end
|
||||
|
||||
function ENT:AITargetInfront( ent, range )
|
||||
if not IsValid( ent ) then return false end
|
||||
if not range then range = 45 end
|
||||
|
||||
local DirToTarget = (ent:GetPos() - self:GetPos()):GetNormalized()
|
||||
|
||||
local InFront = math.deg( math.acos( math.Clamp( self:GetForward():Dot( DirToTarget ) ,-1,1) ) ) < range
|
||||
return InFront
|
||||
return self:AITargetInFront( ent, range )
|
||||
end
|
||||
|
||||
function ENT:CanRechargeShield()
|
||||
|
@ -273,46 +273,45 @@ end
|
||||
|
||||
function ENT:RunAI()
|
||||
local RangerLength = 15000
|
||||
|
||||
|
||||
local mySpeed = self:GetVelocity():Length()
|
||||
local myPos = self:GetPos()
|
||||
local myRadius = self:BoundingRadius()
|
||||
local myDir = self:GetForward()
|
||||
|
||||
|
||||
local MinDist = 1500 + mySpeed
|
||||
local StartPos = self:GetPos()
|
||||
|
||||
local StartPos = self:LocalToWorld( self:OBBCenter() )
|
||||
|
||||
local FrontLeft = util.TraceLine( { start = StartPos, filter = self, endpos = StartPos + self:LocalToWorldAngles( Angle(0,20,0) ):Forward() * RangerLength } )
|
||||
local FrontRight = util.TraceLine( { start = StartPos, filter = self, endpos = StartPos + self:LocalToWorldAngles( Angle(0,-20,0) ):Forward() * RangerLength } )
|
||||
|
||||
|
||||
local FrontLeft2 = util.TraceLine( { start = StartPos, filter = self, endpos = StartPos + self:LocalToWorldAngles( Angle(25,65,0) ):Forward() * RangerLength } )
|
||||
local FrontRight2 = util.TraceLine( { start = StartPos, filter = self, endpos = StartPos + self:LocalToWorldAngles( Angle(25,-65,0) ):Forward() * RangerLength } )
|
||||
|
||||
|
||||
local FrontLeft3 = util.TraceLine( { start = StartPos, filter = self, endpos = StartPos + self:LocalToWorldAngles( Angle(-25,65,0) ):Forward() * RangerLength } )
|
||||
local FrontRight3 = util.TraceLine( { start = StartPos, filter = self, endpos = StartPos + self:LocalToWorldAngles( Angle(-25,-65,0) ):Forward() * RangerLength } )
|
||||
|
||||
|
||||
local FrontUp = util.TraceLine( { start = StartPos, filter = self, endpos = StartPos + self:LocalToWorldAngles( Angle(-20,0,0) ):Forward() * RangerLength } )
|
||||
local FrontDown = util.TraceLine( { start = StartPos, filter = self, endpos = StartPos + self:LocalToWorldAngles( Angle(20,0,0) ):Forward() * RangerLength } )
|
||||
|
||||
local Up = util.TraceLine( { start = StartPos, filter = self, endpos = StartPos + self:GetUp() * RangerLength } )
|
||||
local Down = util.TraceLine( { start = StartPos, filter = self, endpos = StartPos - self:GetUp() * RangerLength } )
|
||||
|
||||
|
||||
local Down2 = util.TraceLine( { start = self:LocalToWorld( Vector(0,0,100) ), filter = self, endpos = StartPos + Vector(0,0,-RangerLength) } )
|
||||
|
||||
|
||||
local cAvoid = Vector(0,0,0)
|
||||
if istable( self.FoundPlanes ) then
|
||||
for _, v in pairs( self.FoundPlanes ) do
|
||||
if IsValid( v ) and v ~= self and v.LFS then
|
||||
local theirRadius = v:BoundingRadius()
|
||||
local Sub = (myPos - v:GetPos())
|
||||
local Dir = Sub:GetNormalized()
|
||||
local Dist = Sub:Length()
|
||||
|
||||
if Dist < (theirRadius + myRadius + 200) then
|
||||
if math.deg( math.acos( math.Clamp( myDir:Dot( -Dir ) ,-1,1) ) ) < 90 then
|
||||
cAvoid = cAvoid + Dir * (theirRadius + myRadius + 500)
|
||||
end
|
||||
end
|
||||
|
||||
for _, v in pairs( LVS:GetVehicles() ) do
|
||||
if v == self then continue end
|
||||
|
||||
local theirRadius = v:BoundingRadius()
|
||||
local Sub = (myPos - v:GetPos())
|
||||
local Dir = Sub:GetNormalized()
|
||||
local Dist = Sub:Length()
|
||||
|
||||
if Dist < (theirRadius + myRadius + 200) then
|
||||
if math.deg( math.acos( math.Clamp( myDir:Dot( -Dir ) ,-1,1) ) ) < 90 then
|
||||
cAvoid = cAvoid + Dir * (theirRadius + myRadius + 500)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -335,29 +334,22 @@ function ENT:RunAI()
|
||||
local TargetPos = (FLp+FRp+FL2p+FR2p+FL3p+FR3p+FUp+FDp+Up+Dp) / 10
|
||||
|
||||
local alt = (myPos - Down2.HitPos):Length()
|
||||
|
||||
|
||||
self._AIFireInput = false
|
||||
|
||||
if alt < 600 then
|
||||
TargetPos.z = myPos.z + 2000
|
||||
else
|
||||
local Target = self:AIGetTarget()
|
||||
|
||||
|
||||
if IsValid( Target ) then
|
||||
local HisRadius = Target:BoundingRadius()
|
||||
local HisPos = Target:GetPos() + Vector(0,0,600)
|
||||
|
||||
|
||||
TargetPos = HisPos + (myPos - HisPos):GetNormalized() * (myRadius + HisRadius + 500) + cAvoid * 8
|
||||
|
||||
local startpos = self:GetRotorPos()
|
||||
local tr = util.TraceHull( {
|
||||
start = startpos,
|
||||
endpos = (startpos + self:GetForward() * 50000),
|
||||
mins = Vector( -30, -30, -30 ),
|
||||
maxs = Vector( 30, 30, 30 ),
|
||||
filter = self
|
||||
} )
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
return TargetPos
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user