BodyVelocity biggest Bug I had

Hello I am creating a DashSystem Rightnow with BodyVelocity.

The Problem is that if I hit a part with BodyVelocity then the HumanoidRootPart is getting Buggy:

https://streamable.com/i968u5

So how can I fix this. I will not send the whole script just the part where I use my BodyVelocity the other things in my script is not important for you:

local bodyVelocity = Instance.new('BodyVelocity', rootPart)
bodyVelocity.Velocity = Vector3.new(0, 0, 0)
bodyVelocity.MaxForce = Vector3.new(0, 0, 0)

    local COOLDOWN = 1
    local DASH_VELOCITY = 25
    local DASH_DURATION = .25
    local LAST_DASH = tick()

    local function SetBodyVelocity(velocity)
    	bodyVelocity.MaxForce = Vector3.new(0, 1, 0)
    	bodyVelocity.Velocity = velocity

    	delay(DASH_DURATION, function()
    		bodyVelocity.Velocity = Vector3.new(0, 0, 0)
    		bodyVelocity.MaxForce = Vector3.new(0, 0, 0)
    	end)
    end

    local GetDirection = {
    	Forward = function()
    		return rootPart.CFrame.LookVector * DASH_VELOCITY
    	end,

    	Backward = function()
    		return rootPart.CFrame.LookVector * -DASH_VELOCITY
    	end,

    	Right = function()
    		return rootPart.CFrame.RightVector * DASH_VELOCITY
    	end,

    	Left = function()
    		return rootPart.CFrame.RightVector * -DASH_VELOCITY
    	end,
    }


    uis.InputBegan:Connect(function(key, locked)
    if locked then return end
    local mixedDirection = Vector3.new(0, 0, 0)

    If Input.KeyCode == Enum.KeyCode.Q then
    for dashKey, directionName in pairs(DashKeys) do
    	if UserInputService:IsKeyDown(dashKey) then
    	local direction = GetDirection[directionName]()
    	mixedDirection += direction
    	end
    	end
        end
    end)

So how can fix this?

3 Likes

you could detect if the player hits a part during the dash thing then stop it

1 Like

how could I do that?

Raycast is not a good way because the HumanoidRootPart could be hitted by his back etc

.Touched could work I guess, you could detect if the torso hits a part

1 Like

I thought that too but woudnt that be too buggy?

1 Like

but thats not a good idea with stopping the dash

1 Like

it would make no sense when the character is stopping after dash or dash is getting destroying

1 Like

It must be the script in my other script I have no problems

Depends on how you’d wanna effect it, looking at the video it seems like the velocity seems to glitch about at the point of impact, so maybe you could implement a invisible part outside the part that you hit? Kinda like a Region if I’m being exact

Keeping in mind, you’re setting the BodyVelocity on the client side so you’ll need to detect it from that side as well:

local COOLDOWN = 1
local DASH_VELOCITY = 25
local DASH_DURATION = .25
local LAST_DASH = tick()

local function SetBodyVelocity(velocity)
	bodyVelocity.MaxForce = Vector3.new(0, 1, 0)
	bodyVelocity.Velocity = velocity

	delay(DASH_DURATION, function()
		bodyVelocity.Velocity = Vector3.new(0, 0, 0)
		bodyVelocity.MaxForce = Vector3.new(0, 0, 0)
	end)
end

local GetDirection = {
	Forward = function()
		return rootPart.CFrame.LookVector * DASH_VELOCITY
	end,

	Backward = function()
		return rootPart.CFrame.LookVector * -DASH_VELOCITY
	end,

	Right = function()
		return rootPart.CFrame.RightVector * DASH_VELOCITY
	end,

	Left = function()
		return rootPart.CFrame.RightVector * -DASH_VELOCITY
	end,
}


uis.InputBegan:Connect(function(key, locked)
    if locked then return end
    local mixedDirection = Vector3.new(0, 0, 0)

    If Input.KeyCode == Enum.KeyCode.Q then
        for dashKey, directionName in pairs(DashKeys) do
        	if UserInputService:IsKeyDown(dashKey) then
            	local direction = GetDirection[directionName]()
            	mixedDirection += direction
        	end
    	end
    end
end)

--Invisible-Part Detection that'll remove the BodyVelocity upon near contact:
local InvisiblePart = workspace.InvisiblePart

InvisiblePart.Touched:Connect(function(Hit)
    if Hit.Parent:FindFirstChild("Humanoid") then
        local Model = Hit.Parent
        if Model.HumanoidRootPart:FindFirstChild("BodyVelocity") then
            Model.HumanoidRootPart.BodyVelocity:Destroy()
        end
    end
end)
2 Likes

but why should I remove this in my other script which I used bodyvelocity it wasnt that kind of buggy?

1 Like

IMPORTANT: THIS IS WAS MY FIRST SCRIPT I CREATED WITH BODYVELOCITY AND IT WASNT THAT BUGGY LIKE THE SCRIPT ABOVE

I used in one of my scripts bodyvelocity too and it wasnt that buggy. Why is the new Script so buggy?
https://streamable.com/j03t6c

local Debris = game:GetService("Debris")
local RunService = game:GetService("RunService")
local CAS = game:GetService("ContextActionService")
local uis = game:GetService("UserInputService")
local Players = game:GetService("Players").LocalPlayer
local Humanoid = Players.Character:WaitForChild("Humanoid")
local HMRP = Players.Character:WaitForChild("HumanoidRootPart")

local Dashing = script:WaitForChild("Dash")
local RightDash = script:WaitForChild("RightDash")
local LeftDash 	= script:WaitForChild("LeftDash")

local Dashanim = Humanoid:LoadAnimation(Dashing)
local Rightanim = Humanoid:LoadAnimation(RightDash)
local Leftanim = Humanoid:LoadAnimation(LeftDash)

local pressQ = false
local pressD = false
local pressA = false
local pressS = false
local pressW = false
local Qprime = false

local Left = false
local Right = false

local Previous = tick()
local CoolDown = 3


local function Dash(studs, look)
	local BodyVelocity = Instance.new("BodyVelocity")
	BodyVelocity.MaxForce = Vector3.new(10000,1,10000) 
	BodyVelocity.Velocity = studs * look
	BodyVelocity.Parent = HMRP
	wait(1)
	BodyVelocity:Destroy()
end

local currentTime = tick()
local cooldown = 3


uis.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.A and pressA == false  then
		pressA = true 
	end
	if input.KeyCode == Enum.KeyCode.D and pressD == false  then
		pressD = true 
	end
	if input.KeyCode == Enum.KeyCode.S and pressS == false then
		pressS = true 
	end
	if input.KeyCode == Enum.KeyCode.W and pressW == false  then
		pressW = true 
	end
	
	
	if input.KeyCode == Enum.KeyCode.Q and Qprime == false and Humanoid.MoveDirection.Magnitude == 0 and tick() - currentTime >= cooldown then
		currentTime = tick()
		print("fail1")
		Qprime = true
		Dashanim:Play()
		Dash(HMRP.CFrame.LookVector, 150)
		wait(CoolDown)
		Qprime = false
	elseif input.KeyCode == Enum.KeyCode.Q and Qprime == false and pressD == false and pressA == false and Humanoid.MoveDirection.Magnitude > 0 and tick() - currentTime >= cooldown then
		currentTime = tick()
		print("fail2")
		Qprime = true
		Dashanim:Play()
		Dash(Humanoid.MoveDirection, 150)
		wait(CoolDown)
		Qprime = false
	elseif input.KeyCode == Enum.KeyCode.Q and pressQ == false and tick() - currentTime >= cooldown then
		currentTime = tick()
		print("fail3")
		pressQ = true
	end
	
end)	

uis.InputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.A and pressA == true then
		pressA = false 
	end
	if input.KeyCode == Enum.KeyCode.D and pressD == true then
		pressD = false 
	end
	if input.KeyCode == Enum.KeyCode.W and pressW == true then
		pressW = false 
	end
	if input.KeyCode == Enum.KeyCode.S and pressS == true then
		pressS = false 
	end
end)


RunService.RenderStepped:Connect(function(player)
	local objectMoveDirection = HMRP.CFrame:VectorToObjectSpace(Humanoid.MoveDirection)
	if pressQ == true then
		if objectMoveDirection.X > 0.5 and Right == false then
			Right = true
		elseif objectMoveDirection.X < -.5 and Left == false then
			Left = true
		end
		if objectMoveDirection.X > 0.5 and pressQ == true and Right == true and Left == false and Qprime == false then
			table.foreach(Players.Character:GetDescendants(),function(i,v)if v:IsA("AnimationTrack") then v:Stop() end end)
			print("Doesntwork1")
			Leftanim:Stop()
			if not Rightanim.IsPlaying then
				Rightanim:Play()
			end
			Dash(Humanoid.MoveDirection, 150)
			table.foreach(Players.Character:GetDescendants(),function(i,v)if v:IsA("AnimationTrack") then v:Play() end end)
			pressQ = false
			Right = false
			Left = false
		elseif objectMoveDirection.X < -0.5  and pressQ == true and Right == false and Left == true and Qprime == false then
			table.foreach(Players.Character:GetDescendants(),function(i,v)if v:IsA("AnimationTrack") then v:Stop() end end)
			print("Doesntwork2")
			Rightanim:Stop()
			if not Leftanim.IsPlaying then
				Leftanim:Play()
			end
			Dash(Humanoid.MoveDirection, 150)
			table.foreach(Players.Character:GetDescendants(),function(i,v)if v:IsA("AnimationTrack") then v:Play() end end)
			pressQ = false
			Right = false
			Left = false
		else
			Rightanim:Stop()
			Leftanim:Stop()
		end
	end
end)

Well I don’t know where exactly you assign your BodyVelocity, so I’m just assuming

Another alternate you could use is using BodyForces instead, I believe those can work a bit more smoother

1 Like

Everything what you need to know is in the script above.

I use BodyVelocity just for my input nomore. And everything where I used BodyVelocity is in the script above. I dont know why it is buggy maybe because of delay.

let me add something I forget to add for BodyVelocity

Chances are that’s just how ROBLOX physics can act possibly

Are you sure you just can’t change to a BodyForce instead? You never know unless you try

1 Like

try destroying the velocity sooner and add more force?

1 Like

Why should I destroy my velocity sooner cuz Roblox physics has some problems?

should I report this bug to Roblox I dont think anyone can solve this problem?

Don’t report it as a bug to ROBLOX unless you do enough experimentation with messing around & confirming it to be an actual bug

1 Like

yes thats true after 2 weeks if nobody could solve it I will report it

because bodyvelocity adds constant force. in the one script you sent you keep the velocity alive for 1 second meaning for an entire second it will apply the force in the direction set for 1 second. that could cause some unwanted behavior when met with an obstacle.

1 Like