- Home /
Question by
LMacalister · May 14 at 12:44 AM ·
c#cameracamera rotatecamera rotationfirst-person
Camera defaulting to -90 Y
When I click play for some reason the camera starts at -90 Y rotation. If I remove the clamp it still rotates to -100+
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MouseCamLook : MonoBehaviour
{
[SerializeField]
public float sensitivity = 5.0f;
[SerializeField]
public float smoothing = 2.0f;
public GameObject character;
private Vector2 mouseLook;
private Vector2 smoothV;
// Start is called before the first frame update
void Start()
{
character = this.transform.parent.gameObject;
}
// Update is called once per frame
void Update()
{
var mouseDelta = new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y"));
mouseDelta = Vector2.Scale(mouseDelta, new Vector2(sensitivity * smoothing, sensitivity * smoothing));
smoothV.x = Mathf.Lerp(smoothV.x, mouseDelta.x, 1f / smoothing);
smoothV.y = Mathf.Lerp(smoothV.y, mouseDelta.y, 1f / smoothing);
mouseLook += smoothV;
mouseLook.y = Mathf.Clamp(mouseLook.y, -90, 90);
transform.localRotation = Quaternion.AngleAxis(-mouseLook.y, Vector3.right);
character.transform.localRotation = Quaternion.AngleAxis(mouseLook.x, character.transform.up);
}
}
Comment
Your answer
Follow this Question
Related Questions
How can I create vertical camera movement?,How can I make vertical camera movement? 1 Answer
I only rotated X, but Y and Z are shifting as well when I play the game. 1 Answer
Limit camera RotateAround for an UAV game 0 Answers
How to make the player direction change with the camera rotation? 1 Answer
How to allow camera to complete an upside down rotation while using LookAt() 0 Answers