Is there a way to clamp AngularVelocity?

I want to clamp the angles on my part between 80 and -80 degrees on the X axis, however I’m not sure on how to do this. Is there even a way to clamp angular velocity since it’s not specific angles, but instead a velocity? All help’s appreciated, thanks!

Velocity would be displayed in an int. So I guess you could use GetPropertyChangedSignal and if it is changed then just make it ‘0’ again.

But how would I know if it reached a specific angle?

1 Like

I believe you can achieve this with CFrame:ToOrientation().

local RNS = game:GetService("RunService")

local part = script.Parent
local angular = part.AngularVelocity

RNS.Stepped:Connect(function()
	local _,x = part.CFrame:ToOrientation()
	x = math.deg(x)

	if x > 80 or x < -80 then
		-- add your clamping code here
	end
end)

Here’s an example of me making the part red when it’s in the clamping range (and white when it’s not).

2 Likes

Thanks for the code, is there a way I can put this on a different axis? Also, when I try to print it, it prints out the wrong orientation. In the inspection is is at 0 degrees, yet the variable says -90. Any reason for this?

1 Like

What do you mean by inspection? Could you show your code?

I meant to say inspector, in the inspector window

local _,x = script.Parent.VehicleSeat.CFrame:ToOrientation()
x = math.deg(x)
	
print(x)

image
image

1 Like

Try this instead:

local x = part.CFrame:ToOrientation()
x = math.deg(x)

I believe that worked. Is there a way to change the axis?

1 Like

:ToOrientation() returns ‘x, y, z’ in that order.

So technically, you can do this:

local x,y,z = part.CFrame:ToOrientation()
x = math.deg(x)
y = math.deg(y)
z = math.deg(z)


I just tried it on the Z axis (which is the up and down for my plane), and it’s always a really long numbers but never really above 1?

Actually nevermind that haha, it’s on the X axis.

There is another problem though. The highest this goes is 89 degrees, then it goes back down to 0 even though I’ve got past vertical?

1 Like

image

What axis are you checking for?

So I’m using the X axis, which is the up and down for my plane

1 Like

That is pretty weird. I’m rotating my part on the X axis and it works fine (after 90, it goes back slowly down).

here’s a video showing it

So any ideas on how I can fix this?