Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Ortron 27
7 years ago

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

0
Camera.CoordinateFrame.lookVector Thundermaker300 554 — 7y

1 answer

Log in to vote
1
Answered by 7 years ago

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

0
Tysm Ortron 27 — 7y
0
Np. KingLoneCat 2642 — 7y
Ad

Answer this question