From 36bc05cde36c486c5796bf32fd5702aae2c25345 Mon Sep 17 00:00:00 2001 From: Stoob Date: Fri, 18 Jun 2021 17:25:31 -0500 Subject: [PATCH 1/2] setAng/Pos to use entity instead of physObj - Allows entities that are parented to be manipulated --- lua/entities/gmod_wire_expression2/core/custom/prop.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/core/custom/prop.lua b/lua/entities/gmod_wire_expression2/core/custom/prop.lua index 849c3c4250..209e5fe6ef 100644 --- a/lua/entities/gmod_wire_expression2/core/custom/prop.lua +++ b/lua/entities/gmod_wire_expression2/core/custom/prop.lua @@ -143,8 +143,8 @@ end function PropCore.PhysManipulate(this, pos, rot, freeze, gravity, notsolid) local phys = this:GetPhysicsObject() if IsValid( phys ) then - if pos ~= nil then WireLib.setPos( phys, Vector( pos[1],pos[2],pos[3] ) ) end - if rot ~= nil then WireLib.setAng( phys, Angle( rot[1],rot[2],rot[3] ) ) end + if pos ~= nil then WireLib.setPos( this, Vector( pos[1],pos[2],pos[3] ) ) end + if rot ~= nil then WireLib.setAng( this, Angle( rot[1],rot[2],rot[3] ) ) end if freeze ~= nil and this:GetUnFreezable() ~= true then phys:EnableMotion( freeze == 0 ) end if gravity ~= nil then phys:EnableGravity( gravity ~= 0 ) end if notsolid ~= nil then this:SetSolid( notsolid ~= 0 and SOLID_NONE or SOLID_VPHYSICS ) end From 063ee27816cd93a44d12dee306f815632f6d46aa Mon Sep 17 00:00:00 2001 From: Stoob Date: Fri, 18 Jun 2021 18:57:52 -0500 Subject: [PATCH 2/2] Add option for interpolated movement - Adds two new functions setPosInterpolated and setAngInterpolated - Allows movement of entities that do not have a physobj --- .../core/custom/cl_prop.lua | 2 ++ .../core/custom/prop.lua | 20 ++++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/core/custom/cl_prop.lua b/lua/entities/gmod_wire_expression2/core/custom/cl_prop.lua index 0b8d21961f..f1d1b0a0f2 100644 --- a/lua/entities/gmod_wire_expression2/core/custom/cl_prop.lua +++ b/lua/entities/gmod_wire_expression2/core/custom/cl_prop.lua @@ -25,6 +25,8 @@ E2Helper.Descriptions["setPos(e:v)"] = "Sets the position of an entity." E2Helper.Descriptions["reposition(e:v)"] = "Deprecated. Kept for backwards-compatibility." E2Helper.Descriptions["setAng(e:a)"] = "Set the rotation of an entity." E2Helper.Descriptions["rerotate(e:a)"] = "Deprecated. Kept for backwards-compatibility." +E2Helper.Descriptions["setPosInterpolated(e:v)"] = "Sets the position of an entity with interpolation." +E2Helper.Descriptions["setAngInterpolated(e:a)"] = "Set the rotation of an entity with interpolation." E2Helper.Descriptions["parentTo(e:e)"] = "Parents one entity to another." E2Helper.Descriptions["parentTo(e:)"] = E2Helper.Descriptions["parentTo(e:e)"] E2Helper.Descriptions["deparent(e:)"] = "Unparents an entity, so it moves freely again." diff --git a/lua/entities/gmod_wire_expression2/core/custom/prop.lua b/lua/entities/gmod_wire_expression2/core/custom/prop.lua index 209e5fe6ef..e7b94deadc 100644 --- a/lua/entities/gmod_wire_expression2/core/custom/prop.lua +++ b/lua/entities/gmod_wire_expression2/core/custom/prop.lua @@ -140,14 +140,18 @@ function PropCore.CreateProp(self,model,pos,angles,freeze,isVehicle) return prop end -function PropCore.PhysManipulate(this, pos, rot, freeze, gravity, notsolid) +function PropCore.PhysManipulate(this, pos, rot, freeze, gravity, notsolid, interpolate) + if pos ~= nil and not interpolate then WireLib.setPos( this, Vector( pos[1],pos[2],pos[3] ) ) end + if rot ~= nil and not interpolate then WireLib.setAng( this, Angle( rot[1],rot[2],rot[3] ) ) end + local phys = this:GetPhysicsObject() if IsValid( phys ) then - if pos ~= nil then WireLib.setPos( this, Vector( pos[1],pos[2],pos[3] ) ) end - if rot ~= nil then WireLib.setAng( this, Angle( rot[1],rot[2],rot[3] ) ) end + if pos ~= nil and interpolate then WireLib.setPos( phys, Vector( pos[1],pos[2],pos[3] ) ) end + if rot ~= nil and interpolate then WireLib.setAng( phys, Angle( rot[1],rot[2],rot[3] ) ) end if freeze ~= nil and this:GetUnFreezable() ~= true then phys:EnableMotion( freeze == 0 ) end if gravity ~= nil then phys:EnableGravity( gravity ~= 0 ) end if notsolid ~= nil then this:SetSolid( notsolid ~= 0 and SOLID_NONE or SOLID_VPHYSICS ) end + phys:Wake() end end @@ -445,6 +449,16 @@ end e2function void entity:rerotate(angle rot) = e2function void entity:setAng(angle rot) +e2function void entity:setPosInterpolated(vector pos) + if not PropCore.ValidAction(self, this, "pos") then return end + PropCore.PhysManipulate(this, pos, nil, nil, nil, nil, true) +end + +e2function void entity:setAngInterpolated(angle rot) + if not PropCore.ValidAction(self, this, "ang") then return end + PropCore.PhysManipulate(this, nil, rot, nil, nil, nil, true) +end + -------------------------------------------------------------------------------- local function parent_check( child, parent )