Skip to content

Commit d921a7c

Browse files
authored
Fix applyTorque world matrix mismatch (#3561)
`PhysObj:ApplyTorqueCenter` expects input multiplied by `q_world_f_core_last_psi`, but `PhysObj:LocalToWorldVector` multiplies input by a matrix interpolated between `q_world_f_core_last_psi` and `q_world_f_core_next_psi`. `AddAngleVelocity` expects local space input which matches the Wiremod `applyTorque` input. We only need to convert torque to velocity dividing it by `rot_inertia`.
1 parent 8159c5f commit d921a7c

1 file changed

Lines changed: 2 additions & 4 deletions

File tree

lua/entities/gmod_wire_expression2/core/entity.lua

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -737,10 +737,8 @@ e2function void entity:applyTorque(vector torque)
737737

738738
local phys = this:GetPhysicsObject()
739739

740-
-- Convert torque from local to world axis
741-
torque = phys:LocalToWorldVector( clamp(torque) )
742-
-- Convert rad*in^2 to deg*m^2
743-
phys:ApplyTorqueCenter( torque * (180 / math.pi / 39.3701^2) )
740+
-- Convert rad*in^2 to deg*m^2 and torque to velocity
741+
phys:AddAngleVelocity( torque * (180 / math.pi / 39.3701^2) * phys:GetInvInertia() )
744742
end
745743

746744
e2function vector entity:inertia()

0 commit comments

Comments
 (0)