Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How could i rotate the character so it faces where the camera is looking?

I know the camera has a CoordinateFrame but i don't know how it can tell which direction it is facing or where it is

1 comment

0

Camera.CoordinateFrame.lookVector

1 answer

✓ Accepted answer

Hey Ortron,

You can simply get the Camera's facing Vector by get it's CFrame's lookVector. Then, once you have that you will need to do some simple Vector math to get the correct direction for your torso to face. Below is a personal example of how this would look.

####Personal Example

local cam = workspace.CurrentCamera         -- Variable for the Camera.
local face = cam.CFrame.lookVector    -- Variable for the direction the Camera's facing.
local torso = workspace.Player1.UpperTorso     -- Variable for the UpperTorso
local torso_pos = torso.Position    -- Variable for the Torso's Position 
torso.CFrame = CFrame.new(torso_pos, Vector3.new(face.X * 9999, torso_pos.Y, face.Z * 9999)) -- Some simple Vector math to make the Character face the correct decision. A CFrame in this case is comprised of 2 Vectors, first being the position and second being the direction. In this case, the position is staying the same since we're simply redirecting the Torso. So, I just simply set that to the Torso's Position and the direction that it was facing is where it got tricky. We want the y direction of the Torso to stay the same since we don't want to change the Torso's y coordinate because we want him to be flat on both his feet I set his x position to the Direction the Camera's facing's X and then multiplied it by 9999 to map it to a 3D Position in space from the lookVector. Same with the Z coordinate.

##Well, I hope you have a nice day/night and I hope I helped.

~~ KingLoneCat

2 comments

0

Tysm

0

Np.

This discussion is preserved as it was. New answers, comments, and votes are closed.