CFrame orientation problem

I looked up a tutorial on viewports and how to place objects inside of them aswell how to display them.
However I’m having trouble with the camera because I want it to be showing the side of the character
and not the front

Original Code

ViewportCamera.CFrame = CFrame.new(PlayerModel.Head.Position + (PlayerModel.Head.CFrame.LookVector*3) + Vector3.new(0,0,0), PlayerModel.Head.Position)

My Attempt

ViewportCamera.CFrame = CFrame.new(PlayerModel.Head.Position + (PlayerModel.Head.CFrame.LookVector*3) * CFrame.fromEulerAnglesYXZ(math.rad(90),0,0), PlayerModel.Head.Position)

I tried using CFrame.fromEulerAnglesYXZ with match.rad, since I thought that would help rotate the camera. But then I get the error “CFrame expected, got Vector3”.

I know this has to do with my lack of understanding, but I just want to know how to make the camera face the right side of the character. Explaining why I got this error would also be very useful.

Hi there!

I looked at a old game project of mine, and the way I did it was like this:

	local cam = Instance.new("Camera")
	cam.CFrame = CFrame.new(object.Head.Position + (object.Head.CFrame.lookVector*viewConfig.Distance.Value) + Vector3.new(viewConfig.X.Value,viewConfig.Y.Value,viewConfig.Z.Value), Vector3.new(object.Head.Position.X, object.Head.Position.Y - 0.75, object.Head.Position.Z))

I’m sure since you now have a “finished recipe” you can change it to your liking. :slight_smile:

Edit: As far as I remember, where the “viewConfig(XYZ)” is, that is the rotation. So most likely, you would just have to have one of them at 90, and the rest on 0

Another edit: Nope, unsure what I did back then, it’s been years. The values was between 0 & 1

1 Like

I tried that before where I changed X,Y, or Z to 90

ViewportCamera.CFrame = CFrame.new(PlayerModel.Head.Position + (PlayerModel.Head.CFrame.LookVector*3) + Vector3.new(90,0,0), PlayerModel.Head.Position)

The code would run, but it would still be facing the front of the character then I tried it by doing;

ViewportCamera.CFrame = CFrame.new(PlayerModel.Head.Position + (PlayerModel.Head.CFrame.LookVector*3) + Vector3.new(math.rad(90),0,0), PlayerModel.Head.Position)

and the results would end up the same

Try this out.

local Cam = ..--Define yourself
Cam.CFrame = CFrame.new(5,0,0) * CFrame.Angles(math.rad(0),math.rad(90),math.rad(0))

The 5 and which rad you have 90 in depends on your objects orientation & position within the viewport.
image

1 Like

I was able to rotate the camera to 90 degress and have it focus on the player’s head. The only problem now is trying to zoom it out of the players head which shouldn’t take too long for me to figure out I hope.
Thank you for your assistance my friend, this definitely helped me out a lot! :+1:

For anyone looking at this post, dealing with the same problem

My Solution

ViewportCamera.CFrame = PlayerModel.Head.CFrame * CFrame.Angles(0,math.rad(-145), 0) * CFrame.new(0, 0, 3)

Just change the number for math.rad for orientation and for the distance change the number in CFrame.new to whatever you want (mine is 3).

1 Like

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