Mason T-2025
Mason T-2025

Reputation: 1

How can I start a project with the camera facing forward?

I am creating a 3d game in Unity with mouse movement to look around, and when I press the play button and move the mouse anywhere, the camera moves to that spot from where it was when I press play. Is there a way to get it to start facing forward no matter where the cursor is when the game actually loads?

Here is my current code

void LateUpdate () {
MouseMove();
}

private void MouseMove()
{
xRot+=Input.GetAxis("Mouse Y")*mouseSensetive;
yRot-=Input.GetAxis("Mouse X")*mouseSensetive;

xCurrRot=Mathf.SmoothDamp(xCurrRot, -xRot, ref xRotVelocity, smoothDampTime);
yCurrRot=Mathf.SmoothDamp(yCurrRot, -yRot, ref yRotVelocity, smoothDampTime);

mainCamera.transform.rotation=Quaternion.Euler(xCurrRot,yCurrRot,0f);
Player.transform.rotation=Quaternion.Euler(0f,yCurrRot,0f);

}

Upvotes: 0

Views: 25

Answers (1)

Hasnain Shaukat
Hasnain Shaukat

Reputation: 379

You could delay running MouseMove() in Update. Use Time.timeSinceLevelLoad.

Upvotes: 0

Related Questions