How to prevent character from flinging?

I’m trying to make a dash system using BodyVelocity, but when the character dashes into a wall, they get fling

local dashing = Instance.new("BoolValue")
		dashing.Name = "Dashing"
		dashing.Parent = StatusFolder

		local dashEndlag = Instance.new("BoolValue")
		dashEndlag.Name = "DashEndlag"
		dashEndlag.Parent = StatusFolder

		Debris:AddItem(dashEndlag, .35)
		Debris:AddItem(dashing, .35)

		local dashVelocity = Instance.new("BodyVelocity")
		dashVelocity.MaxForce = Vector3.new(999999,0,999999)
		dashVelocity.Parent = Character.HumanoidRootPart

		local dashConnection = nil
		dashConnection = RunService.RenderStepped:Connect(function()
			if not dashing.Parent then
				dashConnection:Disconnect()
				dashConnection = nil
				dashVelocity:Destroy()

				local dashCooldown = Instance.new("BoolValue")
				dashCooldown.Name = "DashCooldown"
				dashCooldown.Parent = StatusFolder
				Debris:AddItem(dashCooldown, .25)
				return
			end
			if direction == "Left" then
				dashVelocity.Velocity = Character.HumanoidRootPart.CFrame.RightVector*-70
			elseif direction == "Right" then
				dashVelocity.Velocity = Character.HumanoidRootPart.CFrame.RightVector*70
			elseif direction == "Forward" then
				dashVelocity.Velocity = Character.HumanoidRootPart.CFrame.LookVector*70
			elseif direction == "Back" then
				dashVelocity.Velocity = Character.HumanoidRootPart.CFrame.LookVector*-70
			end
1 Like

Your character gets flung while dashing because the BodyVelocity constantly pushes the humanoidrootpart at a high speed, When it collides with a wall, Roblox’s physics tries to resolve the collision. The combination of high velocity + MaxForce + constant frame updates can catapult the character. Essentially, the physics engine can’t handle the abrupt stop from a solid wall while the BodyVelocity keeps applying full force. So I’d suggest you either do:

  1. Raycast ahead before applying (or during) velocity

  2. Apply a short impulse instead of constant velocity
    something like
    dashVelocity.Velocity = directionVector * 70 task.delay(0.1, function() dashVelocity.Velocity = Vector3.zero end)

Let me know if you need anymore help on deciding or scripting a fix. (I’ve only given suggestions)

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.