How to change a plane's pitch whilist not changing the roll?

This would be the plane normally
grafik

And I want it to gradually go up like this
grafik
grafik

However, when I change the pitch ingame, it does this instead


grafik

It’s like pressing CTRL + L when rotating, it wont be relative to the parts current orientation. What do I do?

It’s because you’re not setting the pitch relative to part’s CFrame.

Let’s start with part where it’s rotated +30 degrees on it’s roll Z-axis relative to the world.

You want to change it’s pitch (X-axis) value by +30 degrees while keeping it’s roll same relative to the part, however you can’t just add +30 to the X-axis directly as doing so would change it’s pitch relative to world instead of the part.

So we have to apply the +30 degree pitch where we assume part’s position and rotation is the origin (the 0, 0, 0 point), then transform part’s new rotation that’s relative to new origin we set back to it’s world-relative rotation.

This is where CFrame:ToWorldSpace comes in. This method takes part’s world position and rotation as the origin (0, 0, 0 point), then apply the passed CFrame (in this context, the rotation) relative to this origin, then convert the new CFrame to be relative to WorldRoot's origin:

local part = workspace.Part 

--CFrame.Angles uses radians for rotational values. 
--Pi radians equals to 180 degrees, so we divide it by 6 to get the 30 degrees we want.
part.CFrame = part.CFrame:ToWorldSpace(CFrame.Angles(math.pi/6, 0, 0))

I’m not sure if I conveyed it correctly, my English is not that good when it comes to math terms.

1 Like