Issue with body velocity

so i was making a dash system, where when a player presses a key then a body velocity is cloned into them, problem is that whenever I used the dash ability it sometimes puts me into the ground.
like its not moving the character complete straight its sorta moving them towards the ground

local rs = game:GetService("ReplicatedStorage")
local dashevent = rs:WaitForChild("Dash")

dashevent.OnServerEvent:Connect(function(plr)
	local chr = plr.Character
	local rootpart = chr.PrimaryPart
	local bv = Instance.new("BodyVelocity")
	bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
	bv.Velocity = rootpart.CFrame.LookVector * 50
	bv.Parent = rootpart
	task.wait(0.3)
	bv:Destroy()
end)

local script Is

local uis = game:GetService("UserInputService")
local rs = game:GetService("ReplicatedStorage")
local dashevent = rs:WaitForChild("Dash")
local player = game:GetService("Players").LocalPlayer
local chr = player.Character
local hum = chr:WaitForChild("Humanoid")
local debounce = false
uis.InputBegan:Connect(function(input,e)
	if e then return end
	if input.KeyCode == Enum.KeyCode.Q and debounce == false then
		debounce = true
		local dashanim = game:GetService("ReplicatedFirst").Animations.DashAnim
		local dashtrack = hum:LoadAnimation(dashanim)
		dashtrack:Play()
		task.wait(0.2)
		dashevent:FireServer()
		task.wait(0.5)
		dashtrack:Stop()
		task.wait(1)
		debounce = false
	end
end)

If the player has a running animation and it makes the humanoidrootpart look down then it’ll do that, but try setting the bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge)

to this

bv.MaxForce = Vector3.new(math.huge, 0,  math.huge)
1 Like

while the above works, it is effectively clamping the y to zero and the result velocity may not be at full speed (50)

we can maintain the full speed velocity by first clamping y on the look vector, then get its unit vector.

local lookVector = rootpart.CFrame.LookVector
bv.Velocity = Vector3.new(lookVector.X, 0, lookVector.Z).Unit * 50
1 Like

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