# How would i make a good rotational system using only 2 keys?

So im working on a building system atm, and for rotating parts im currently using 3 keys to turn each XYZ orientation axis, and i realized that this isnt the best way to do it and can be done with just 2 keys, like the roblox studio building keys R and T can rotate a part perfectly by flipping the part either up or to the side.

So ive been trying to do research and figuring out how to do this and i have no clue how to even get this. Would i use orientation and check if the part is rotated in a specific way and then rotate it in a certain direction? or is there something i can use to rotate the part? i dont really know thats why im asking for help.

right now all im doing is

``````if inp.KeyCode == Enum.KeyCode.R then
if rotx >= 360 then
rotx = 90
else
rotx += 90
end
elseif inp.KeyCode == Enum.KeyCode.T then
if roty >= 360 then
roty = 90
else
roty += 90
end
elseif inp.KeyCode == Enum.KeyCode.Y then
if rotz >= 360 then
rotz = 90
else
rotz += 90
end
end
``````

which is just a simple way to change the orientation of the part, rotx,roty,rotz being the XYZ of the parts orientation axis.

and yes ive tried just using 2 axis like X and Y for orientation and it doesnt work since it doesnt let me turn the part in certain directions.

I’m pretty sure you can just have one key rotate on one axis and the other key rotate on another one. E.g.

``````if ink.KeyCode == Enum.KeyCode.R then
thing.CFrame *= CFrame.Angles(math.pi/2, 0, 0)
elseif ink.KeyCode == Enum.KeyCode.T then
thing.CFrame *= CFrame.Angles(0, math.pi/2, 0)
end
``````
1 Like

i have no idea how this worked but i tried doing something similar where i would just change 2 of the angles like this:

``````if inp.KeyCode == Enum.KeyCode.R then
if rotx >= 360 then
rotx = 90
else
rotx += 90
end
elseif inp.KeyCode == Enum.KeyCode.T then
if roty >= 360 then
roty = 90
else
roty += 90
end
end
end
``````

and then

``````cf = CFrame.new(MosX,mosY,MosZ)*CFrame.Angles(math.rad(rotx),math.rad(roty),0)
``````

and it wouldnt work… but anyway thanks lol.