How to make BasePart.Velocity with MaxForce

I want to make a strafe/dash script. I’ve tried doing HumanoidRootPart.Velocity = vector3, but that lacks a max force and would fling me when dashing on an edge, and with BodyVelocity, it only dashes in a linear rate with no fiction and gravity applied to it. How do I do this?

1 Like

So just to clarify, you’re planning to use a BodyVelocity object in the HumanoidRootPart to make the player dash, correct?

Assuming this is true, you probably want to limit the BodyVelocity’s max force to the local forward direction so that it doesn’t affect other forces (like gravity).

Yes, with BodyVelocity, but I want to keep the gravity, mass, and fiction too so that it moves from fast to slow according to the weight of player

Great, so BodyVelocity takes a MaxForce with X, Y, and Z components. You want to restrict that force to only act in the positive Z direction relative to the HumanoidRootPart’s orientation. I think BodyVelocity.MaxForce = desiredMagnitude * -HumanoidRootPart.CFrame.LookVector should work for this.

Edit: You’ll want to update the MaxForce every time the character changes direction

local addedVelocity = 10 -- change this
local maxForceMagnitude = 250 -- change this

local HRP = script.Parent.HumanoidRootPart

local bv = Instance.new("BodyVelocity")
bv.Velocity = Vector3.new(addedVelocity,addedVelocity,addedVelocity)
bv.MaxForce = Vector3.new(0,0,0)
bv.Parent = HRP

script.Parent.Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
	bv.MaxForce = maxForceMagnitude * HRP.CFrame.LookVector
end)
1 Like