I am trying to make a “braking” system for a CylindricalConstraint rotating wheel parts. The idea is that when you press the corresponding button the CylindricalConstraint will lock up the wheels. The only issue I am having is that there is not a way to truly “lock” the constraint as far as I know.
I have attempted to create a system where it just applies a high torque and angular velocity in the opposite direction, then test the body’s velocity until it reaches near 0, however, it isn’t very accurate and doesn’t accomplish what I am attempting to do, as it essentially just spins the wheels in the opposite direction until it reaches a certain velocity.
brakes = RunService.RenderStepped:Connect(function(dt)
if UserInputService:IsKeyDown(tune.PBrakeKey) and not braking then
braking = true
if body.AssemblyLinearVelocity.Magnitude <= 10 then return end
for i, cylindrical in ipairs(cylindricals) do
cylindrical.MotorMaxTorque = tune.PBrakeForce
if cylindrical.AngularVelocity >= 0 then
cylindrical.AngularVelocity = -100
else
cylindrical.AngularVelocity = 100
end
end
repeat task.wait() until body.AssemblyLinearVelocity.Magnitude <= 10
for i, cylindrical in ipairs(cylindricals) do
cylindrical.MotorMaxTorque = tune.IdleTorque
cylindrical.AngularVelocity = 0
end
elseif not UserInputService:IsKeyDown(tune.PBrakeKey) then
braking = false
end
end)