Locking CylindricalConstraint MotorMaxTorque/AngularVelocity

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)

Also, the coded block in the post is not what I want at all. Ideally the system would just lock the contraint. Something like cylindrical:LockMotor() would be the parallel of what I am attempting. If that is not possible, however, then I need help with a system that would imitate a lock.

Hey! In order to lock the wheels up in braking, we must apply our our “desired” AngularVelocity with a torque that is larger than the drive torque of the vehicle.

To make the wheels lock up:
cylindrical.MotorMaxTorque = MaxBrakeTorque (or BrakeForce * WheelRadius)
cylindrical.AngularVelocity = 0

This will force the motor to output a high amount of torque in order to make the wheel hit an AngularVelocity of 0.

I hope this helped!

1 Like

This helped me not only find the answer to my problem, but also understand more about what the properties of a CylindricalConstraint actually do. Thank you so much!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.