Need to read how fast a part is rotating on a local axis

Hi!
I need to read how fast a parts is rotating on a local axis as shown in the Image.
image
I how I made it clear what it is I want to read.

Are you rotating it with a force or some kind of CFrame rotation?

local lastCFrame = Obj.CFrame
game:GetService("RunService").Heartbeat:connect(function (dT)
	local currentCFrame = Obj.CFrame
	local axis, angle = (currentCFrame * lastCFrame:inverse()):ToAxisAngle()
	--> Axis [Vec3] and Angle [Number] of the change in angle between this and the last frame => use as a measure of Angular Velocity

end)

where Obj is your part

Could you please explain what the axis, angle variables do?

I take it back, you’re more likely to want this:

local Obj = game.Workspace.Part


local pitch, yaw, roll = Obj.CFrame:toEulerAnglesXYZ()
local States = {
	eulers   = {
		pitch = pitch;
		yaw   = yaw;
		roll  = roll;
	},
	velocity = {
		pitch = 0;
		yaw   = 0;
		roll  = 0;
	}
}

game:GetService("RunService").Heartbeat:connect(function (dT)
	local currentCFrame = Obj.CFrame
	local pitch, yaw, roll = Obj.CFrame:toEulerAnglesXYZ()
	
	States.velocity = {
		pitch = (pitch - States.eulers.pitch)/dT;
		yaw   = (yaw - States.eulers.yaw)/dT;
		roll  = (roll - States.eulers.roll)/dT;
	}
	States.eulers = {pitch = pitch; yaw = yaw; roll = roll}
	
	table.foreach(States.velocity, print)
end)

If you’re using a Cylinder BasePart then look at States.velocity.pitch and you’ll get the AngularVelocity in the direction a cylinder would roll

When I print the yaw changes to a negative number halfway through a rotation.

Pretty sure there’s a rotation velocity property for parts.
Part.RotVelocity

sorry I miss read, I thought it said yaw instead of pitch

There’s Rot Velocity but its relative to the world, I need to now the angular momentum relative to the object

I’m hoping that means it’s woking now?

Now it prints out 0 except every half rotation, where it prints out ~200. The motor which the object is attached to is set to 1.

Oh this is on an unanchored part e.g. a wheel? Just do this if you want object space:

local Obj = game.Workspace.Part

game:GetService("RunService").Heartbeat:connect(function (dT)
local AngularVel = Obj.CFrame:VectorToObjectSpace(Obj.RotVelocity)
print("in obj space:", AngularVel)
end)
1 Like

It works now, thank you so much for the help :smiley:

1 Like

No worries, glad the solution helped :slight_smile: