Counter acting forced acted upon an object

I’m trying to make a vehicle system of some sort and i’m stuck on basically the simplest thing. Here’s the simplified version of it. How do I make the ball not go down the hill?

I’ve figured just to calculate the force and then applying a vector force in the opposite direction. (I’ve set it to no friction)

local pVel = Vector3.new()

game["Run Service"].Heartbeat:Connect(function(dt)
	local vel = script.Parent.AssemblyLinearVelocity
        -- f = ma, where a = (v_f - v_0)/t
	local force = script.Parent:GetMass() * (vel-pVel)/dt

	script.Parent.Attachment.VectorForce.Force = -force

	pVel  = vel
end)

but this doesnt seem to work at all. can someone give me a hand?

1 Like

It’d be preferrable if you didn’t use a VectorForce for this, actually.
Roblox’s deltaTime is incredibly inconsistent, which can lead to jitters in some cases such as with higher FPS, which really, really sucks. Though, here’s the solution I found which was able to completely stop the ball’s motion:

local RunService = game:GetService("RunService")
local Workspace = game:GetService("Workspace")

local ball = script.Parent
local vectorForce: VectorForce = ball.VectorForce
-- Calculating this in PreSimulation since it's before physics are applied
RunService.PreSimulation:Connect(function(delta: number): ()
	local vel = ball.AssemblyLinearVelocity
	-- I just negate the ball's current velocity and counteract gravity like this
	local force = (vel / -delta) + Vector3.new(0, Workspace.Gravity, 0)
	vectorForce.Force = ball:GetMass() * force
end)

I’d suggest looking into LinearVelocity if you want to completely counteract all force.

1 Like

You can just anchor the ball.

ball.Anchored = true
1 Like