Rotate object relevant to the way a player is looking at it

I want to rotate a part relative to the way a player is looking at it (for example, 45 degrees right). Example:

player looks at part from the front, it rotates like this:

player looks at part from the side, it rotates like this:
image

I have tried rotating the part but it always seems to rotate the part relative to the global X Y or Z axis.

1 Like


how part should be rotated from front

image
how part should be rotated from side

1 Like

there’s 2 ways i could think of doing this:

part.CFrame = Camera.CFrame - Camera.CFrame.Position + part.Position

and

part.CFrame = CFrame.LookAt(part.Position, Camera.CFrame.Position)
1 Like

If I understand correctly, wouldn’t these lines make the part look at the player? If so, I do not want the part to look at the player, I want it rotate based on the way a player looks at it.

1 Like

so if i understand correctly you want the part to face the player, not the camera. right?

I’ll make it a bit easier to understand. Say a part is already facing the player (in player’s perspective, the part is lined up). Now I want the part to rotate 45 degrees to the right.

1 Like

image

Just like this, now I want the part to rotate 45 degrees to the right.

1 Like

something like:

part.CFrame = CFrame.LookAt(part.Position, Character.HumanoidRootPart.CFrame.Position * CFrame.angles(45,0,0))

right?

1 Like

Something like that, but not quite. It still rotates on the global X axis.

1 Like

hey! appologies for the late reply, i got what you wanted here!

local lookVector = (humanoidRootPart.Position - part.Position).Unit
part.CFrame = CFrame.new(part.Position, part.Position + lookVector)
3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.