How do I limit the velocity of VectorForce?

But what is ‘ForceValue’?

Its just a variable. Should’ve put local behind it, lol

Yeah I know, but like I don’t understand how this one line correlates to max speed? It’s just a vector3.new variable.

F = ma, and hence constant force will provide constant acceleration. You need to either use LinearVelocity or figure out when to make the force 0 so that acceleration also becomes 0 and velocity remains constant (I don’t think attaining constant velocity is possible using VectorForce due to factors such as drag, friction etc).

Maybe you can use :GetPropertyChangedSignal() to look at the AssemblyLinearVelocity of the part for changes and update the force accordingly.

This post should help you, I think. I personally use BodyVelocity most of the time, and sometimes LinearVelocity

The thing with ALV, is that it it’s the velocity within Vector3 and not the velocity itself, so it’s harder to work with that.

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.

23 Likes

Do I have to make it relative to world? I made mine relative to attachment0.

Yep for the drag force as drag force is relative to Assembly Linear Velocity direction which is in world space.

For the movement it’s up to you, mine is because Humanoid move direction is relative to world.

1 Like

Can you also explain to me what is this line for?

local XZVector = Vector3.new(1,0,1)

Oh that’s being multiplied in order to make the drag force only happen for the XZ plane when you are moving left and right.

Since it’s being multiplied it makes the Y zero and hence makes the drag force not happen at all when you are falling down and up. Unless you want a some sort of parachute effect.

i am sorry i didnt notice that. i am in elementry :smiling_face_with_tear: so i dunno what drag is tho i understood what it is now.
But he just wants a force limiter on a vector force so he should be good with a while loop but @dthecoolest 's method is better as it allows more customization

1 Like

Sorry, but what is “Unit”? Is this meant to be a defined variable already?

Unit is a vector with the length of one, hence one unit.

it describes the direction of the drag force.

-velocity.Unit

The rest is a factor on how much to increase this drag force in this direction.

--drag factor, depends on speed
(speed^2)*XZVector

Oh because the error I’m getting is saying ‘Unit is not a valid member of VectorForce’.

Try mine once. It should work but i still strongly reccomend you to solve the error.
(also you do VectorForce.Force.Unit)

I don’t understand the code, what do you mean by
Vector3.new(YourDesiredClampValue`sX,YourDesiredClampValue`sY,YourDesiredClampValue`sZ?

I need explanation for things.

For some reason, doing this causes my car to spin and turn oddly.

You might want to apply drag to the center of mass then.

https://developer.roblox.com/en-us/api-reference/class/VectorForce

Also checking out the direction of the force is good like the relative to options.

Oh, would I also do the same for the vectorForce?