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:
or
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!
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.