Skip to content

Commit 65ff4de

Browse files
authored
Merge pull request #358 from OffLegAz/OffLegAz-patch-6
Improvments to vendors PhysicsObjects and their collision
2 parents 7926b72 + 4ac9fa6 commit 65ff4de

File tree

2 files changed

+28
-20
lines changed

2 files changed

+28
-20
lines changed

plugins/vendor/entities/entities/ix_vendor.lua

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,13 @@ function ENT:Initialize()
1919
self:SetUseType(SIMPLE_USE)
2020
self:SetMoveType(MOVETYPE_NONE)
2121
self:DrawShadow(true)
22-
self:SetSolid(SOLID_BBOX)
23-
self:PhysicsInit(SOLID_BBOX)
22+
self:InitPhysObj()
23+
24+
self:AddCallback("OnAngleChange", function(entity)
25+
local mins, maxs = entity:GetAxisAlignedBoundingBox()
26+
27+
entity:SetCollisionBounds(mins, maxs)
28+
end)
2429

2530
self.items = {}
2631
self.messages = {}
@@ -31,13 +36,6 @@ function ENT:Initialize()
3136
self:SetDescription("")
3237

3338
self.receivers = {}
34-
35-
local physObj = self:GetPhysicsObject()
36-
37-
if (IsValid(physObj)) then
38-
physObj:EnableMotion(false)
39-
physObj:Sleep()
40-
end
4139
end
4240

4341
timer.Simple(1, function()
@@ -47,6 +45,25 @@ function ENT:Initialize()
4745
end)
4846
end
4947

48+
function ENT:InitPhysObj()
49+
local mins, maxs = self:GetAxisAlignedBoundingBox()
50+
local bPhysObjCreated = self:PhysicsInitBox(mins, maxs)
51+
52+
if (bPhysObjCreated) then
53+
local physObj = self:GetPhysicsObject()
54+
physObj:EnableMotion(false)
55+
physObj:Sleep()
56+
end
57+
end
58+
59+
function ENT:GetAxisAlignedBoundingBox()
60+
local mins, maxs = self:GetModelBounds()
61+
mins = Vector(mins.x, mins.y, 0)
62+
mins, maxs = self:GetRotatedAABB(mins, maxs)
63+
64+
return mins, maxs
65+
end
66+
5067
function ENT:CanAccess(client)
5168
local bAccess = false
5269
local uniqueID = ix.faction.indices[client:Team()].uniqueID

plugins/vendor/sh_plugin.lua

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,7 @@ if (SERVER) then
8686

8787
entity:SetModel(v.model)
8888
entity:SetSkin(v.skin or 0)
89-
entity:SetSolid(SOLID_BBOX)
90-
entity:PhysicsInit(SOLID_BBOX)
91-
92-
local physObj = entity:GetPhysicsObject()
93-
94-
if (IsValid(physObj)) then
95-
physObj:EnableMotion(false)
96-
physObj:Sleep()
97-
end
89+
entity:InitPhysObj()
9890

9991
entity:SetNoBubble(v.bubble)
10092
entity:SetDisplayName(v.name)
@@ -287,8 +279,7 @@ if (SERVER) then
287279
data = {uniqueID, entity.classes[uniqueID]}
288280
elseif (key == "model") then
289281
entity:SetModel(data)
290-
entity:SetSolid(SOLID_BBOX)
291-
entity:PhysicsInit(SOLID_BBOX)
282+
entity:InitPhysObj()
292283
entity:SetAnim()
293284
elseif (key == "useMoney") then
294285
if (entity.money) then

0 commit comments

Comments
 (0)