#ApplyImpulse momentum abruptly ends

1 messages · Page 1 of 1 (latest)

mighty meteor
#

I want my knockback system to shove the player back and up which it does do but it reaches a certain position where the momentum just stops instead of slowing dowing over time
here is my test knockback code

local horizontalPower = 100
local verticalPower = 30

function module.HitKnockback(attacker : Model, target : Model)
    local attackerRoot = attacker:FindFirstChild("HumanoidRootPart")
    local targetRoot = target:FindFirstChild("HumanoidRootPart")
    
    local diff = targetRoot.Position - attackerRoot.Position
    local horizontalDir = (diff * Vector3.new(1, 0, 1)).Unit 
    local verticalDir = Vector3.new(0, 1, 0)
    local knockbackDir = ((horizontalDir * horizontalPower) + (verticalDir * verticalPower))
    targetRoot:ApplyImpulse(knockbackDir * targetRoot.AssemblyMass)
end
wheat wadi
# mighty meteor I want my knockback system to shove the player back and up which it does do but ...

Solution 1: Add Drag to the HumanoidRootPart:
function module.HitKnockback(attacker: Model, target: Model)
local attackerRoot = attacker:FindFirstChild("HumanoidRootPart")
local targetRoot = target:FindFirstChild("HumanoidRootPart")

if not attackerRoot or not targetRoot then return end

-- Set drag to make movement slow down over time
targetRoot.CustomPhysicalProperties = PhysicalProperties.new(
    0, -- Density
    1, -- Friction
    2 -- **Drag (higher = slows faster)**
)

local diff = targetRoot.Position - attackerRoot.Position
local horizontalDir = (diff * Vector3.new(1, 0, 1)).Unit
local verticalDir = Vector3.new(0, 1, 0)
local knockbackDir = (horizontalDir * horizontalPower) + (verticalDir * verticalPower)

targetRoot:ApplyImpulse(knockbackDir * targetRoot.AssemblyMass)

end

lapis shoreBOT
#

studio** You are now Level 1! **studio

wheat wadi
#

Solution 2: Use BodyVelocity (Gradual Slowdown):
local horizontalPower = 100
local verticalPower = 30
local knockbackDuration = 0.5 -- seconds

function module.HitKnockback(attacker: Model, target: Model)
local attackerRoot = attacker:FindFirstChild("HumanoidRootPart")
local targetRoot = target:FindFirstChild("HumanoidRootPart")

if not attackerRoot or not targetRoot then return end

local diff = targetRoot.Position - attackerRoot.Position
local horizontalDir = (diff * Vector3.new(1, 0, 1)).Unit
local knockbackVelocity = (horizontalDir * horizontalPower) + Vector3.new(0, verticalPower, 0)

-- Create BodyVelocity
local bodyVelocity = Instance.new("BodyVelocity")
bodyVelocity.Velocity = knockbackVelocity
bodyVelocity.MaxForce = Vector3.new(4000, 4000, 4000) -- High force to ensure movement
bodyVelocity.Parent = targetRoot

-- Fade out velocity over time for a smooth stop
for i = 1, 10 do
    wait(knockbackDuration / 10)
    bodyVelocity.Velocity = bodyVelocity.Velocity * 0.8 -- Reduce by 20% each step
end

bodyVelocity:Destroy()

end

#

Solution 3: Combine Impulse + BodyVelocity (Best of Both Worlds):
function module.HitKnockback(attacker: Model, target: Model)
local attackerRoot = attacker:FindFirstChild("HumanoidRootPart")
local targetRoot = target:FindFirstChild("HumanoidRootPart")

if not attackerRoot or not targetRoot then return end

local diff = targetRoot.Position - attackerRoot.Position
local horizontalDir = (diff * Vector3.new(1, 0, 1)).Unit
local verticalDir = Vector3.new(0, 1, 0)
local knockbackDir = (horizontalDir * horizontalPower) + (verticalDir * verticalPower)

-- Initial sharp impulse
targetRoot:ApplyImpulse(knockbackDir * targetRoot.AssemblyMass)

-- Follow-up force for smooth travel
local bodyVelocity = Instance.new("BodyVelocity")
bodyVelocity.Velocity = knockbackDir * 0.3 -- 30% of original force
bodyVelocity.MaxForce = Vector3.new(2000, 2000, 2000)
bodyVelocity.Parent = targetRoot

game:GetService("Debris"):AddItem(bodyVelocity, 0.4) -- Auto-destroy after 0.4s

end

#

Solution 4: Adjust Physics Service Settings (Global Fix):
-- Run this once at startup
local PhysicsService = game:GetService("PhysicsService")
PhysicsService.AirFriction = 0.1 -- Higher = more drag in air
PhysicsService.WaterFriction = 0.2

mighty meteor