Garry's Mod Wiki

CTakeDamageInfo:SetDamageForce

  CTakeDamageInfo:SetDamageForce( Vector force )

Description

Sets the directional force of the damage.

This function only affects entities using the VPHYSICS movetype. This means players and most NPCs won't receive the force vector you provide as knockback.

If the entity taking damage is using the WALK or STEP holdtypes, the damage force is instead automatically calculated. It will push the entity away from the inflictor's Entity:WorldSpaceCenter, scaling the push by a calculated value involving the total amount of damage and the size of the entity. Source

To disable knockback entirely, see EFL_NO_DAMAGE_FORCES or use the workaround example below.

Arguments

1 Vector force
The vector to set the force to.

Example

Workaround for player knockback quenching.

local ent = Entity(1) local oldvel = ent:GetVelocity() -- Damage taking example local dmgi = DamageInfo() dmgi:SetDamageType( DMG_RADIATION ) dmgi:SetDamage( 5 ) dmgi:SetAttacker( Entity(0) ) dmgi:SetInflictor( Entity(0) ) ent:TakeDamageInfo( dmgi ) local newvel = ent:GetVelocity() ent:SetVelocity( oldvel - newvel )