Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by bakos · Jan 21, 2014 at 09:34 AM · rotationangleground detection

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 :(

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 :(

I'm stucckkkk!

//

Thank you once again! Sincerely,

Bakos

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by hirenkacha · Jan 21, 2014 at 10:32 AM

 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;
     }
     
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Rotation circle to stop at a certain angle 1 Answer

Angle to Rotation 2 Answers

0-360 Y degree from Vector3.Angle 1 Answer

Issue finding an angle with trigonometry 1 Answer

2D Torque rotation - stop at certain angle 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges