How do I limit the velocity of VectorForce?

Hi there, I have a car that uses the VectorForce constraint to move the car forward and backwards. The issue is, is that the car doesn’t reach a limit and rather keeps getting faster infinitely. Is there a way to limit the velocity of VectorForce or the car itself, and how? I don’t know any other attempt in order to this, as there are limited attributes in achieving this

5 Likes

This topic has been talked about before

1 Like

VectorForce.MaxForce property can help you here.

I don’t simply understand it however.

There’s no MaxForce property in VectorForce, it exists in LinearVelocity

oh sorry my bad i was just checking dev wiki and realized it.
you would need to have a while loop

while wait() do
if VectorForce.Force => Vector3.new(YourDesiredClampValue`sX,YourDesiredClampValue`sY,YourDesiredClampValue`sZ) then
Vector3.force = Vector3.new((YourDesiredClampValue`sX,YourDesiredClampValue`sY,YourDesiredClampValue`sZ)
end
end

Create a maxspeed for the Vectoforce using math.clamp() and turn the force off when it reaches that speed

1 Like

Can you link me the source of where you found that, please?

nah its just simple logic. roblox has a max speed property for most physics constraints. i just dont use that stuff most of the time so i forgot that VectorForce doesnt have a Max Speed Property.

Try adding a drag force in a new vector force factor that will counteract the movement force.

local vehicleVelocity= vehicle.AssemblyLinearVelocity
local dragFactor = 1 -- Just some number try adjusting it
local dragForce = -dragFactor *vehicleVelocity*vehicleVelocity
dragVectorForce.Force = dragForce 

Hes using a VectorForce not ALV. also you should use :ApplyImpulse in such cases.
also thats gonna result in -velocity as you are squaring the velocity and then making it negative.

How would I create a maxspeed; how do I find out the speed?

ForceValue = Vector3.new(x , y ,z)

Use an if statement to see if the `vectorforce has reached said speed

I’lll try this script soon.

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