Player teleporting when being knockbacked

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)

1 Like

you can use velocity it feels more natural idk.

local part = script.Parent  -- The part that triggers the knockback
local knockbackDistance = 100  -- 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


			root.Velocity = root.CFrame.LookVector * - knockbackDistance
		end
	end
end

part.Touched:Connect(onTouched)
1 Like

Thank you! However, I already fixed it. It was moving on the world axis rather than the players axis so it created this jiggery movement with the camera as it was trying to correct the Humanoids Position. Also, running into objects caused it to break as well, so I had the players HumanoidRootPart anchored whenever I moved it via script.