Skip to content

Commit

Permalink
Distance checks and make lever girthier
Browse files Browse the repository at this point in the history
  • Loading branch information
thegrb93 committed May 7, 2020
1 parent 9fe6b13 commit e49586c
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions lua/entities/gmod_wire_lever.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,21 @@ if CLIENT then

local isClicking = LocalPlayer():KeyDown(IN_USE) or LocalPlayer():KeyDown(IN_ATTACK)
if isClicking and not self.wasClicking and IsValid(self.csmodel) then
local rayPos = util.IntersectRayWithOBB(
LocalPlayer():GetShootPos(),
LocalPlayer():GetEyeTrace().Normal * 75,
self.csmodel:GetPos(),
self.csmodel:GetAngles(),
self.csmodel:OBBMins(),
self.csmodel:OBBMaxs()
)
if rayPos then
net.Start("wire_lever_activate")
net.WriteEntity(self)
net.SendToServer()
local aimPos = LocalPlayer():GetShootPos()
if aimPos:DistToSqr(self:GetPos())<160^2 then
local rayPos = util.IntersectRayWithOBB(
aimPos,
LocalPlayer():GetAimVector() * 160,
self.csmodel:GetPos(),
self.csmodel:GetAngles(),
self.csmodel:OBBMins() - Vector(2,2,2),
self.csmodel:OBBMaxs() + Vector(2,2,2)
)
if rayPos then
net.Start("wire_lever_activate")
net.WriteEntity(self)
net.SendToServer()
end
end
end
self.wasClicking = isClicking
Expand Down Expand Up @@ -123,7 +126,7 @@ else
if not IsValid(ply) or not IsValid(ent) or not ent.Use or ent:GetClass() ~= "gmod_wire_lever" then return end
if IsValid(ent.User) then return end

if ply:GetShootPos():Distance(ent:GetPos()) < 100 then
if ply:GetShootPos():DistToSqr(ent:GetPos()) < 160^2 then
ent:Use(ply, ply, USE_ON, 1)
end
end)
Expand Down

0 comments on commit e49586c

Please sign in to comment.