How would I go about rotating a part on 2 axes while keeping the third locked?

  1. What do you want to achieve?
    I want to have the top surface of the green part below face the red part but by only pitching a rolling, and keeping it’s relative Y axis rotation at 0.

  1. What is the issue?
    When the red part passes over the green part, the green part flips, which is unwanted.

Flipping Behavior

  1. What solutions have you tried so far?
    Originally, I have been using the CFrame lookat constructor, but I have also attempted to use CFrame.fromMatrix(), but I haven’t been able to figure out how I would use that to solve my problem.

Using the CFrame lookat constructor, I can limit the green part to only rotating on one axis (the z axis) by doing:

local UpRightAngle = CFrame.Angles(math.rad(90), 0, 0) --To point the top surface toward the red part instead of the front surface.
local DirectionalVector = (greenpart.Position - redpart.Position).Unit * Vector3.new(1, 1, 0)
greenpart.CFrame = CFrame.new(greenpart.Position, greenpart.Position + DirectionalVector) * UpRightAngle

but this does not solve my problem, because I want the green part to be able to rotate on both it’s relative z and x axes.

1 Like