Please allow constraint.Keepupright to work on custom entities. At the moment the function is hard coded to only work on prop_physics or on prop_ragdoll entities. In a local test I did (bypassed the check), I have seen that the KeepUpright constraint works just fine on custom scripted entities.
--[[----------------------------------------------------------------------
Keepupright( ... )
Creates a KeepUpright constraint
------------------------------------------------------------------------]]
function Keepupright( Ent, Ang, Bone, angularlimit )
if ( !CanConstrain( Ent, Bone ) ) then return false end
if ( Ent:GetClass() != "prop_physics" && Ent:GetClass() != "prop_ragdoll" ) then return false end
if ( !angularlimit or angularlimit < 0 ) then return end
local Phys = Ent:GetPhysicsObjectNum( Bone )
-- Remove any KU's already on entity
RemoveConstraints( Ent, "Keepupright" )
onStartConstraint( Ent )
local Constraint = ents.Create( "phys_keepupright" )
ConstraintCreated( Constraint )
Constraint:SetAngles( Ang )
Constraint:SetKeyValue( "angularlimit", angularlimit )
Constraint:SetPhysConstraintObjects( Phys, Phys )
Constraint:Spawn()
Constraint:Activate()
onFinishConstraint( Ent )
AddConstraintTable( Ent, Constraint )
local ctable = {
Type = "Keepupright",
Ent1 = Ent,
Ang = Ang,
Bone = Bone,
angularlimit = angularlimit
}
Constraint:SetTable( ctable )
--
-- This is a hack to keep the KeepUpright context menu in sync..
--
Ent:SetNWBool( "IsUpright", true )
return Constraint
end
Requested change
Please remove the class check if possible.
Alternatively add an additional entity parameter such as entity.AllowKeepupright that will also pass that check. This would work as a static property for SENTs and also work as a dynamic property for every kind of entity. Implementation details are up to you, the property can be named differently if needed.
-- ...
if ( !CanConstrain( Ent, Bone ) ) then return false end
if ( !Ent.AllowKeepupright && Ent:GetClass() != "prop_physics" && Ent:GetClass() != "prop_ragdoll" ) then return false end
if ( !angularlimit or angularlimit < 0 ) then return end
-- ...
About
Please allow constraint.Keepupright to work on custom entities. At the moment the function is hard coded to only work on
prop_physics
or onprop_ragdoll
entities. In a local test I did (bypassed the check), I have seen that the KeepUpright constraint works just fine on custom scripted entities.Wiki for context
https://wiki.facepunch.com/gmod/constraint.Keepupright
Code for context
Affected code:
lua/includes/modules/constraint.lua:617 (dev branch)
Requested change
Please remove the class check if possible.
Alternatively add an additional entity parameter such as
entity.AllowKeepupright
that will also pass that check. This would work as a static property for SENTs and also work as a dynamic property for every kind of entity. Implementation details are up to you, the property can be named differently if needed.