My dash system doesnt work well

  1. **I trying to make basic dash system

  2. **it works well only for just q but for q + a and q + d doesnt works for direction

  3. **I tried rootPart.CFrame.RightVector * Vector3.new(150, 0, 0) , rootPart.CFrame.RightVector + Vector3.new(150, 0, 0) , Vector3.new(-150, 0, 0)

-- local UserInputService = game:GetService("UserInputService")

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local rootPart = character:WaitForChild("HumanoidRootPart")
local db = false
local cooldown = 5

local keysPressed = {}

UserInputService.InputBegan:Connect(function(input, gameProcessed)
	if not gameProcessed then
		keysPressed[input.KeyCode] = true

		if not db then
			
			if keysPressed[Enum.KeyCode.A] and keysPressed[Enum.KeyCode.Q] then
				rootPart.Velocity = rootPart.CFrame.LookVector * Vector3.new(-150, 0, 0)
				db = true
				task.wait(cooldown)
				db = false
		
			elseif keysPressed[Enum.KeyCode.D] and keysPressed[Enum.KeyCode.Q] then
				rootPart.Velocity = rootPart.CFrame.LookVector * Vector3.new(150, 0, 0)  
				db = true
				task.wait(cooldown)
				db = false
				
			elseif keysPressed[Enum.KeyCode.Q] then
				rootPart.Velocity = rootPart.CFrame.LookVector * -150 
				db = true
				task.wait(cooldown)
				db = false
			end
		end
	end
end)

UserInputService.InputEnded:Connect(function(input, gameProcessed)
	if not gameProcessed then
		keysPressed[input.KeyCode] = false
	end
end)

1 Like

Instead of using the HumanoidRootPart’s LookVector you could use the Humanoid MoveDirection that way it will consider the direction the player is wanting to move.

You could also add a check to see if the MoveDirection’s magnitude is 0 and default to the normalized forward direction (which is 0,0,-1). That will allow the player to dash forward when still

1 Like

The issue with your current implementation is the misuse of the LookVector and combination of directions.

  1. You should be using RightVector and LookVector correctly for direction.
  2. You need to adjust the velocity to take into account the proper combination of directions.

I’ve tested this in Studio. Let me know if this is what you were looking for:

local UserInputService = game:GetService("UserInputService")

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local rootPart = character:WaitForChild("HumanoidRootPart")
local db = false
local cooldown = 5

local keysPressed = {}

UserInputService.InputBegan:Connect(function(input, gameProcessed)
	if not gameProcessed then
		keysPressed[input.KeyCode] = true

		if not db then
			if keysPressed[Enum.KeyCode.A] and keysPressed[Enum.KeyCode.Q] then
				-- Dash left
				rootPart.Velocity = rootPart.CFrame.RightVector * -150
				db = true
				task.wait(cooldown)
				db = false

			elseif keysPressed[Enum.KeyCode.D] and keysPressed[Enum.KeyCode.Q] then
				-- Dash right
				rootPart.Velocity = rootPart.CFrame.RightVector * 150
				db = true
				task.wait(cooldown)
				db = false

			elseif keysPressed[Enum.KeyCode.Q] then
				-- Dash backward
				rootPart.Velocity = rootPart.CFrame.LookVector * -150
				db = true
				task.wait(cooldown)
				db = false
			end
		end
	end
end)

UserInputService.InputEnded:Connect(function(input, gameProcessed)
	if not gameProcessed then
		keysPressed[input.KeyCode] = false
	end
end)
2 Likes

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