metastruct-experiments/heat_seeking_minori.lua
Ayane Satomi 9e5616fc7d sanitize whitespaces
Signed-off-by: Ayane Satomi <ayane@vignetteapp.org>
2022-04-20 03:11:52 +08:00

32 lines
No EOL
875 B
Lua

-- Code by Henke and Minori
-- to remove the hook please run
-- hook.Remove("StartCommand", "autopilot")
local target = eno
say("[luadev/Autopilot] Now following " .. tostring(target))
hook.Add("StartCommand", "heatseekingminori", function(ply, cmd)
if ply ~= LocalPlayer() then return end
if not target:Alive() then return end
if target:GetPos():Distance(ply:GetPos()) < 128 then
return
end
-- we wanna run if our target is greater than 512 units
-- that way we can still catch up
if target:GetPos():Distance(ply:GetPos()) > 512 then
cmd:AddKey(IN_SPEED)
cmd:SetForwardMove(ply:GetRunSpeed())
else
cmd:SetForwardMove(ply:GetWalkSpeed())
end
local ang = cmd:GetViewAngles()
local targetAngle = (target:GetShootPos() - ply:GetShootPos()):GetNormalized():Angle()
targetAngle = LerpAngle(0.1, ang, targetAngle)
cmd:SetViewAngles(targetAngle)
end)