How to reset camera angle when disabling/disabled

Perfect answer sir. Thank you very much!

Now just another quick extra question for you. Would you know how to reset a mouseLook’s axis AFTER it is disabled?
And/or reset the axis on the mouseLook, THEN disable it, so when my player leaves that trigger point, the camera isn’t looking the way he was last looking?

Haha hard to explain.

If you didn’t understand, basically what i would like to achieve is:

Player is out of trigger : mouseLook axes is MouseX&MouseY.

Player enters trigger : mouseLook axes is MouseY.

Player exits trigger : mouseLook yRotation is reset and axes is MouseX&MouseY again.

See what i’ve got going right now is my player has 2 mouselook scripts. mLook && mLook2.

//

mLook = MouseX(Player)

mLook2 = MouseY(Players eyeballs)

//

Now when a bool value called “detected” is true, mLook2 is enabled && you can spin the character on the X axis while looking up and down on the Y, like a normal FPS game.
ONLY PROBLEM IS: When that bool becomes false, it’s supposed to:

  1. reset my rotationY to 0.

  2. turn off mLook2.

So hopefully i end up with only mLook active and my players eyeballs are facing forward.

//

I’ve looked around on google and unity answers for a possible solution but i cannot find anything that works.

I’ve tried storing the rotationY’s original rotation and applying it when that bool is false, but it doesn’t reset until i reactivate mLook2(when detected becomes true).

I’ve also tried setting it to 0 manually after detected is false, but still nothing.

//

Heres my code:

if(groundDetect == false)
		{
			reset = true;
			mLook2 = GetComponent<mLook2>();
			mLook2.axes = mLook2.RotationAxes.MouseXAndY;
			JetPack = GetComponent<jetPack>();
			JetPack.enabled = true;
			rigidbody.velocity = Vector3.zero;
		}	
		if(groundDetect == true)
		{
			mLook = GetComponentInChildren<mLook>();
			mLook.enabled = true;
			mLook2 = GetComponent<mLook2>();
			mLook2.axes = mLook2.RotationAxes.MouseX;
			JetPack = GetComponent<jetPack>();
			JetPack.enabled = false;
			rigidbody.AddForce(-gravity*rigidbody.mass*myNormal);
		}
		if(reset)
		{
			mLook = GetComponentInChildren<mLook>();
			mLook.rotationY = mLook.rotationYset2;
			//mLook.enabled = false;
		}
		else
		{

		}

now this all works if i have the last line(mLook.enabled = false) commented out, but it stutters the camera due to the update every frame. Players move faster than that sooo i can’t have it change the rotation every frame :frowning:

What i really need is a solution where it will find that mLook2, set its rotationY to 0(facing foward) && disable mLook2 so i can just use mLook.

//

If there is any solution out there for my problem PLEASE help me out here :frowning:

I’m stucckkkk!

//

Thank you once again!
Sincerely,

Bakos

using UnityEngine;
using System.Collections;

public class InputAxis : MonoBehaviour
{
	public bool xAxis = true;
	private float mouseX=0f;
	private float mouseY=0f;
	public float X_MouseSensitivity=5f; //x movement sensitivity
	public float Y_MouseSensitivity=5f; //y movement sensitivity
        private Quaternion desiredRotation;
	void Start ()
	{
		xAxis=true;
	}
	
	void Update ()
	{
		if(xAxis)
		{
			mouseX+=Input.GetAxis("Mouse X")*X_MouseSensitivity;
		}
		else
		{
			mouseX+=Input.GetAxis("Mouse X")*X_MouseSensitivity;
			mouseY-=Input.GetAxis("Mouse Y")*Y_MouseSensitivity;
            desiredRotation = Quaternion.Euler(0f,0f,0f);
            Camera.main.transform.rotation=Quaternion.Slerp(Camera.main.transform.rotation,desiredRotation,10f*Time.deltaTime);
		}
		
	}
	
	void OnTriggerEnter (Collider col)
	{
		xAxis=false;
	}
	void OnTriggerExit (Collider col)
	{
		xAxis=true;
	}
	
}