How do I limit the velocity of VectorForce?

It’s intended for use even without assembly linear velocity, it works as a formula of drag.

image

It’s simplified so everything else is a constant, area, drag, density.

Yep -velocity is intended because drag force acts in the opposite direction of movement.

But yeah I think the formula is a bit incorrect it results in a weird error.

This should be the fixed formula:

		dragForce.Force = -velocity.Unit*(speed^2)*XZVector

@vxsqi Example script, insert into starter character scripts, pretty fun for testing:

local char = script.Parent
local humanoid : Humanoid = char:WaitForChild("Humanoid")
local rootPart = humanoid.RootPart
local UserInputService = game:GetService("UserInputService")

local attachment = Instance.new("Attachment",rootPart)

local vectorForce = Instance.new("VectorForce")
vectorForce.Attachment0 = attachment
vectorForce.Force = Vector3.new()
vectorForce.RelativeTo = Enum.ActuatorRelativeTo.World
vectorForce.Parent = char

humanoid.PlatformStand = true


local dragForce = Instance.new("VectorForce")
dragForce.Attachment0 = attachment
dragForce.Force = Vector3.new()
dragForce.RelativeTo = Enum.ActuatorRelativeTo.World
dragForce.Parent = char

local XZVector = Vector3.new(1,0,1)
while task.wait() do
	local velocity = rootPart.AssemblyLinearVelocity
	local speed = velocity.Magnitude
	print(speed)
	vectorForce.Force = humanoid.MoveDirection*1000

--the drag force section
	if speed > 0.1 then
		dragForce.Force = -velocity.Unit*(speed^2)*XZVector
	else
		dragForce.Force = Vector3.new()
	end
end

Without drag force, speed goes to 60 and above:

With drag force speed caps at 11.

29 Likes