How to correctly limit BodyGyro from rotating X and Y axes

I’m having a problem with limiting a BodyGyro from rotating the X and Y axes of a part. I want the part to be able to rotate on the Z axis so that when a player steps on the part, the part will only rotate on the Z axis but not on any other axis. This will be done using a BodyPosition and a BodyGyro, but it seems to not be working.

This is what the function for creating the BodyMovers for the Part looks like:

local function PhysicsAnchoredPart(Part)
	local Position = Instance.new("BodyPosition", Part);
	Position.MaxForce = Vector3.new(1, 1, 1) * math.huge;
	Position.Position = Part.Position;
	local BodyGyro = Instance.new("BodyGyro", Part);
	BodyGyro.MaxTorque = Vector3.new(
		Part:FindFirstChild("LockY") and math.huge or 0, 
		Part:FindFirstChild("LockX") and math.huge or 0, 
		Part:FindFirstChild("LockZ") and math.huge or 0
	);
	BodyGyro.CFrame = CFrame.new(Part.Position, Part.Position + Part.CFrame.LookVector);
	Part.Anchored = false;
end

This is what the part looks like in game:

There is another method of doing this using a hinge, but I’m not sure why this method doesn’t work? The part has IntValues named “LockY” and “LockX”, and the part also is oriented in a way where rotation in the Z axis should not change its LookVector. Why does it start moving frantically like that when there is a force applied to it by a character?

1 Like

I suggest looking at AlignOrientation instead because you can make it rigid using AlignOrientation | Roblox Creator Documentation to prevent XY axis movement and you can control which axis it rotates in using AlignOrientation | Roblox Creator Documentation.

1 Like

Thanks for the reply, this definitely solves my problem but I’m still looking for an explanation as to why this method wouldn’t work.

Hmm, shouldn’t it be LockY and LockZ instead of LockX based on how you input them into max torque?

Y axis rotation should be zero. X rotation and Z rotation should be the one with math.huge applied onto them.

That’s what I was thinking and I tried changing it, but the Part is oriented with the front of the part facing the next platform, so theoretically it should still work either way.
I tried changing the part’s mass to 0 thinking that it was the rotational inertia from the force of the character standing on the platform, and this is what happened:

https://gyazo.com/86c1df5bd0b69795bd41131d457b75c1

It acts more like how I want it to but it sometimes completely rotates 180 degrees in the X axis because of gimbal lock. So I’m pretty sure the issue was because of both rotational intertia and gimbal lock.