How to prevent it from bouncing off the wall when I use the dash function

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    How to prevent it from bouncing off the wall when I use the dash function

  2. What is the issue? Include screenshots / videos if possible!
    The dash function works well, but when it touches the wall during the dash, the character flies away.

  3. What solutions have you tried so far? Did you look for solutions on the Creator Hub?
    I don’t know how to solve it

local Template = {}

Template.Config = {
    Cooldown = 1,
}

local VelocityDuration = 0.1 -- Unused

function Template.Execute(player)
    local character = player.Character
    
    if character == nil then    return end
    
    local humanoidRootPart =  character:FindFirstChild("HumanoidRootPart")
    if humanoidRootPart == nil then return end
    
    local humanoid = character:FindFirstChild("Humanoid")
    if humanoid == nil then return end
    if humanoid.Health <= 0 then return end

    
    local linearVelocity = Instance.new("LinearVelocity")
    linearVelocity.Attachment0 = humanoidRootPart.RootAttachment
    linearVelocity.MaxForce = 100000
    linearVelocity.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
    linearVelocity.VectorVelocity = Vector3.new(0,0,-100)
    linearVelocity.Parent = humanoidRootPart
    
    task.wait(0.1)
    
    linearVelocity:Destroy()
    
    
    return true
end

return Template

When a user presses e key and receives a remote event from the server, this function is executed

Detect when you touch something and destroy the linear velocity

you can try lowering the max force of the linearvelocity, i’ve seen my friend do it to fix something exactly like this for his game

I had this problem for a landing system where I would bounce on the ground, I fixed it by:

  • Reducing the MaxForce like @pasoowor said.
  • Using RayCasting to detect the floor (in your case the X & Z axis / the LookVector of the user) and then applying a counter force / removing all linear force when you get too close.

Something preliminary like:

local dashForce = 10000

function Template.Execute (player)
	local character = player.Character

	if character == nil then
		return
	end

	local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
	if humanoidRootPart == nil then
		return
	end

	local humanoid = character:FindFirstChild("Humanoid")
	if humanoid == nil then
		return
	end
	if humanoid.Health <= 0 then
		return
	end

	local function isAboutToHitPart ()
		local params = RaycastParams.new()
		params.FilterDescendantsInstances = { character:GetDescendants() }
		params.FilterType = Enum.RaycastFilterType.Exclude

		local inFront = workspace:Raycast(humanoidRootPart, Vector3.new(0, 0, -3), params)

		return inFront and true or false
	end

	-- Prevent dash into part.
	if isAboutToHitPart() then
		return
	end

	local linearVelocity = Instance.new("LinearVelocity")
	linearVelocity.Attachment0 = humanoidRootPart.RootAttachment
	linearVelocity.MaxForce = dashForce
	linearVelocity.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
	linearVelocity.VectorVelocity = Vector3.new(0, 0, -100)
	linearVelocity.Parent = humanoidRootPart

	local checker = RunService.Heartbeat:Connect(function (deltaTime)
		if isAboutToHitPart() then
			linearVelocity.VectorVelocity = Vector3.new(0, 0, 0)
		end
	end)

	task.delay(0.1, function ()
		checker:Disconnect()
		linearVelocity:Destroy()
	end)

	return true
end