Hey! I’m currently making a boss battle for my Roblox Game and was attempting to program a kick. The animations are working great but I decided to do the knockback part in a different script, then integrate it. The problem is whenever the HumanoidRootPart is moved back on it’s own axis it starts making the camera SUPER jiggery and even in some cause just straight up teleporting the player. I have a video below displaying the problem:
robloxapp-20250130-1125350.wmv (2.1 MB)
The goal of the code is to move the player back 10 studs upon them touching a part. Changing the amount of steps does not help solve the issue. Code:
local part = script.Parent -- The part that triggers the knockback
local knockbackDistance = 10 -- Distance to push the player back
local duration = 0.5 -- Time for the movement to complete
local steps = 100 -- Number of steps for smoothing
local function onTouched(otherPart)
local character = otherPart.Parent
if character and character:FindFirstChild("HumanoidRootPart") then
local root = character.HumanoidRootPart
local humanoid = character:FindFirstChild("Humanoid")
if humanoid then
local rootCF = root.CFrame
local backDirection = -rootCF.LookVector -- Moves backward relative to the character
local targetPosition = rootCF.Position + (backDirection * knockbackDistance)
-- Smooth movement using a loop
for i = 1, steps do
local alpha = i / steps -- Progress (0 to 1)
local easingFactor = 1 - (1 - alpha) ^ 3 -- Easing out function (fast to slow)
local newPosition = rootCF.Position:Lerp(targetPosition, easingFactor)
root.CFrame = CFrame.new(newPosition) * CFrame.Angles(0, rootCF:ToEulerAnglesYXZ())
task.wait(duration / steps) -- Wait a short time for smooth motion
end
end
end
end
part.Touched:Connect(onTouched)