Rotating part with BodyAngularVelocity is buggy

I’m sorry if the answer seems obvious or anything, I just can’t find a way to fix this.

I’m trying to rotate a part whenever a player pressed the A or D keys using BodyAngularVelocity. It kind of works, but it’s super buggy.

Here is my script: (sorry if the code isn’t very good, I was just trying to throw together something quick)

workspace.CurrentCamera.CameraSubject = workspace.Car
workspace.Car.Name = game:GetService("Players").LocalPlayer.Name.." Car"
local uis = game:GetService("UserInputService")
local car = workspace:FindFirstChild(game:GetService("Players").LocalPlayer.Name.." Car")

uis.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.D then
			print("d")
			car.right.MaxTorque = Vector3.new(4000,999999999999,4000)
		elseif input.KeyCode == Enum.KeyCode.A then
			print("a")
			car.left.MaxTorque = Vector3.new(4000,999999999999,4000)
		end
	end
end)

uis.InputEnded:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.D then
			print("d up")
			car.right.MaxTorque = Vector3.new(0,0,0)
		elseif input.KeyCode == Enum.KeyCode.A then
			print("a up")
			car.left.MaxTorque = Vector3.new(0,0,0)
		end
	end
end)

Whenever I press D to turn right, it either doesn’t move at all or hops a little right before just stopping again. For some reason, when I press A to turn left it never works at all.

Here is a video of me attempting to rotate it: (whenever my character moves right I’m pressing D, whenever my character moves left I’m pressing A, obviously)

So how can I (preferably) use BodyAngularVelocity to rotate the part without it acting buggy like this?

2 Likes

Hmm, I’m not quite sure. Although when ever I used BodyAngularVelocity, I usually set the AngularVelocity (or Velocity, not sure what it’s called) to move in whatever direction I want. It seems you’re using MaxTorque instead of setting the AngularVelocity property directly. I think your issue is because of that. But, I’m not sure. I’d definitely try doing this instead and seeing if you notice a difference. It has been awhile since I’ve worked with this BodyMover, so forgive me if this information is not helpful.

I’m not sure either, but it might be because you set MaxTorque instead of setting the AngularVelocity as @C_Sharper said. I believe you should put MaxTorque to Vector3.new(inf, inf, inf) in the start of the script (and keep it as inf). When pressing A, rotate the part to the left and when pressing D rotate the part to the right.

@C_Sharper, @C_onfident

Okay, I’ll try that out.

@C_Sharper, @C_onfident I changed the script so that it sets AngularVelocity, and I set MaxTorque on both objects to inf,inf,inf however the same thing is still happening.

Hm, that’s really strange then…not sure what else to tell you other than it might be a bug with the physics solver. Not sure at all though.

Do you need to be using BodyAngularVelocity for this? You could CFrame the part instead.

I mean, I guess I could try CFraming it. I’ll look into it now.

It would eliminate the buggy glitchy feel and would probably be better because (correct me if I’m wrong) body objects are no longer actively maintained (again I could be wrong)

It seems like you’re making a car and therefore, I don’t recommend CFraming it. I do, however recommend using a BodyGyro because in my opinion, it’s a lot easier to use.

Yeah I thought CFraming wouldn’t be the best for a car, so I’ll look into BodyGyro!

1 Like