In my scene, I have my character facing a certain direction, with a camera attached. Now, when I press play, for some reason, the character immediately faces the other way. I've tried turning the model and camera to face the opposite way of that, to make up for it, but it still faces that same direction.
I've had a look at the script for the camera, but I'm not sure what could be causing this to happen. There's no target assigned that should cause that reaction, as the camera is a child of the player.
Below is a copy of my script:
public class FirstPersonCamera : MonoBehaviour
{
Vector2 mouseLook;
Vector2 smoothV;
public float sensitivity = 5.0f;
public float smoothing = 2.0f;
GameObject character;
void Start()
{
character = transform.parent.gameObject;
Debug.Log("Camera is operating");
}
void Update()
{
var md = new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y"));
md = Vector2.Scale(md, new Vector2(sensitivity * smoothing, sensitivity * smoothing));
smoothV.x = Mathf.Lerp(smoothV.x, md.x, 1f / smoothing);
smoothV.y = Mathf.Lerp(smoothV.y, md.y, 1f / smoothing);
mouseLook += smoothV;
transform.localRotation = Quaternion.AngleAxis(-mouseLook.y, Vector3.right);
character.transform.localRotation = Quaternion.AngleAxis(mouseLook.x, character.transform.up);
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = true;
if (Input.GetKeyDown("escape"))
{
Cursor.lockState = CursorLockMode.Locked;
}
}
}
Does anyone see what could be causing this issue? I've using Unity version 2019.2
I'm also including screenshots of the player's position, as well as the camera's.
Player:
Camera:
There's something in the script that is causing the character to turn around, as I placed the script on another model and it had the same effect P: