How can I make the player dash a certain amount of studs forward without going through walls?

The following script triggers way too late and you’d have already gone through the wall by the time the tween cancels. I hope you understand what I’m trying to do.

local root = game.Players.LocalPlayer.Character.HumanoidRootPart
local tween = game:GetService("TweenService"):Create(
    root, 
    TweenInfo.new(.1, Enum.EasingStyle.Sine, Enum.EasingDirection.In), 
    {CFrame = character.HumanoidRootPart.CFrame*CFrame.new(0,0,-20)}
)
			
root.Touched:Connect(function(part)
	if part.Anchored and part.CanCollide then
		tween:Cancel()
	end
end)
			
wait(.2)
			
tween:Play()

You could insert a body velocity into the HumanoidRootPart. Just call the function when you want them to dash.

local speed = 10
local dashTime = 1

local player = game.Players.LocalPlayer
local debounce = false

local function Dash()
       if  not debounce then
             debounce = true
             local BV = Instance.new("BodyVelocity", player.Character.HumanoidRootPart)
             BV.Velocity = player.Character.HumanoidRootPart.CFrame.LookVector * speed
             wait(dashTime)
             BV:Destroy()
             db = false
       end
end
1 Like