- Home /
Make Third Person Character Rotate
Hi, after tons of research and no answers, i have decided to make my first post and see how it goes :)
I am trying to create a very specific Third Person Character controller, but instead of it being like most third person shooters where the camera can look around the player, i would like the character to rotate with the camera (which is moved by the mouse x and y) so that the characters front is always facing away from the camera. A good example would be: https://youtu.be/rmtBOPHHQCY?t=273 or https://youtu.be/m1w8jehDrzo?t=408
Take a look at some of he Gameplay above and as you can see, the character is rotating with the camera and always facing the crosshair, in the middle.
So is there anyone out there who would be able to point me in the right direction? Any help is appreciated. Thanks in advance!
Answer by unidad2pete · Sep 02, 2017 at 07:30 PM
You need adjust the next tips to your preferences but the base is this:
Makes a new empty gameObject child of your player, this child we named CamX. Makes a new empty gameObject child of CamX , named CamY, add the camera to this gameObject, and move the position and rotation like you want.
public float mouseSpeed = 3;
public Transform player;
public Camera yourCam;
private void Update()
{
float X = Input.GetAxis("Mouse X") * mouseSpeed;
float Y = Input.GetAxis("Mouse Y") * mouseSpeed;
player.Rotate(0, X, 0); // Player rotates on Y axis, your Cam is child, then rotates too
// To scurity check to not rotate 360º
if (yourCam.transform.eulerAngles.x + (-Y) > 80 && yourCam.transform.eulerAngles.x + (-Y) < 280)
{ }
else
{
yourCam.transform.RotateAround(player.position, yourCam.transform.right, -Y);
}
}
This is not perfect, do you need adjust positions, angles and maybe other postion to rotate Around that not is player. But you can get the idea.
Thanks for your answer, I'll try this when I get the chance
@unidad2pete Wow working perfectly thanks mate solved my problem..sad how the person never came back to upvote your answer but one little question ..why do we need the "camx"and "camy"? the code worked fine without those or did i miss something...
Your answer
Follow this Question
Related Questions
Unity Asset Prefab Bug ThirdPersonController (left rotating bug / Snapping forward Always) 3 Answers
My Obstacle Rotations Are Not Correct 0 Answers
Third Person Shooter (TPS) aiming like Uncharted / MaxPayne3 0 Answers
Setting up Animation for Third Person Controller 0 Answers
How can I turn the direction of bicycle in unity with animations. 0 Answers