Linear Velocity kills the character

I want to achieve a deepwoken-like dodge, where the character gets propelled in the direction it’s going

The issue is, ~50% of the time the character gets sent to the void and deleted? I tried looking on devforum, but couldn’t find anything.

I tried changing it to VectorForce, but it stopped working whatsoever.

Here’s the dodge part of the script:

Remotes.Combat.Dodge.OnServerEvent:Connect(function(plr)
	local char = plr.Character
	local Humanoid:Humanoid = char.Humanoid
	local HRP = char.HumanoidRootPart
	
	if char:GetAttribute("DodgeCooldown") == true then	
		return
	end
	
	
	local attachment = Instance.new("Attachment") 
	attachment.Parent = HRP
	
	local velocity = Instance.new("LinearVelocity")
	
	velocity.Parent = HRP
	velocity.Attachment0 = attachment
	
	velocity.MaxForce = 10000
	
	char:SetAttribute("DodgeCooldown",true)
	char:SetAttribute("Dodging",true)
	
	if Humanoid.FloorMaterial == Enum.Material.Air then -- The thing that is probably causing this
		-- later
		
	else 
		
		
		
		local i = 0
		repeat task.wait(0.05)
			
			i += 1
			velocity.VectorVelocity = Vector3.new(Humanoid.MoveDirection.Unit.X,0,Humanoid.MoveDirection.Unit.Z) * 45
			
		until i == 10
		
	end

	velocity:Destroy()
	





	char:SetAttribute("Dodging",false)
	
	local cor = coroutine.create(function()
		task.wait(1.25)
		char:SetAttribute("DodgeCooldown",false)
	end)
	coroutine.resume(cor)
	
end)

And a video of the issue:
(I’m pressing the dodge button on this one, couldn’t find a decent keyboard visualizer)

(sorry for the goofy video size)
This is how it’s supposed to work:

2 Likes

You forgot to check if Humanoid.MoveDirection.Magnitude > 0. The problem is that using .unit on a vector3 value equivalent to Vector3.new(0,0,0) will return a nan value or something and when your character’s velocity is set to nan or infinite it sends you very far away. What I would do is make it so you can’t dodge while not moving. I can’t provide code or anything since I’m on mobile at the time of writing this.

1 Like

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