Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
This question was closed Jun 15, 2018 at 08:57 AM by Harinezumi for the following reason:

The question is answered, right answer was accepted

avatar image
2
Question by Harinezumi · Mar 15, 2016 at 02:59 PM · rotationfirst person controllermouse look

How to control mouse look of standard First Person Controller? [Unity 5.x]

Hey there!

I'm using the FPSController.prefab Standard Asset from the Characters package, and I would like to modify the rotation of my FPSController. However, the MouseLook object in FPSController stores its own target rotation, so it will overwrite my desired rotation.

For example, I the below TunrPlayer() function doesn't make sense, because MouseLook.LookRotation() will overwrite the player rotation:

 public void TurnPlayer(FirstPersonController player, float angle) {
     player.transform.rotation *= Quaternion.Euler(0, angle, 0);
 }


 public void LookRotation(Transform character, Transform camera)
 {
     float yRot = CrossPlatformInputManager.GetAxis("Mouse X") * XSensitivity;
     float xRot = CrossPlatformInputManager.GetAxis("Mouse Y") * YSensitivity;

     m_CharacterTargetRot *= Quaternion.Euler (0f, yRot, 0f);
     m_CameraTargetRot *= Quaternion.Euler (-xRot, 0f, 0f);

    // skipping some irrelevant lines...

     character.localRotation = m_CharacterTargetRot;
     camera.localRotation = m_CameraTargetRot;

     // skipping some more irrelevant lines...
 }

I tried writing extending the FirstPersonController script with the below method, but it does not solve my problem:

 public void ResetMouseLook() {
     m_MouseLook.Init(transform, m_Camera.transform);
 }


 // this MouseLook.Init() exists in MouseLook.cs by default
 public void Init(Transform character, Transform camera)
 {
     m_CharacterTargetRot = character.localRotation;
     m_CameraTargetRot = camera.localRotation;
 }

What I'm trying to achieve is that if the FirstPersonController's transform is rotated the MouseLook script should respect it, and rotate with it. What am I missing here? How could I gain better control over the MouseLook?

Thanks, Harinezumi

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

  • Sort: 
avatar image
3
Best Answer

Answer by spood · Jul 10, 2016 at 09:43 PM

I ran into this exact same issue when I added cutscenes. My goal was to use the FPS controller as the camera for the cutscene, and then give control back to the player.

You have the right idea to update the m_CharacterTargetRot and m_CameraTargetRot inside MouseLook. When the FirstPersonController calls LookRotation() inside MouseLook, it will use these updated values.

There's a second part that I was getting stuck on. Changing the rotations of them to the new transforms ends up on a tilted axis if you don't lock the X and Z axis on both the camera and character. Although from what I understand the camera should have a locked Y and Z axis, but this wasn't working for me, only the X and Z axis locking worked, not sure why.

Anyway, this way worked for me. Hope this helps anyone else looking into it:

Inside FirstPersonController:

     private void Update ()
     {
         if(cutsceneManager.isInCutscene) {
             RotateViewCutscene();
             return; 
         }
 
         RotateView ();

         // other FPS controller code
     }
 
     private void RotateViewCutscene()
     {
         m_MouseLook.LookRotationCutscene (transform, m_Camera.transform);
     }
 
     private void RotateView ()
     {
         m_MouseLook.LookRotation (transform, m_Camera.transform);
     }

Inside MouseLook:

     public void LookRotationCutscene(Transform character, Transform camera)
     {
         m_CharacterTargetRot = character.localRotation;
         m_CameraTargetRot =  camera.localRotation;
     }

And for completions sake, this is when I do the rotation inside my cutscene:

             Quaternion targetRotation = Quaternion.LookRotation(targetPosition - thing.transform.position);

             // lock x and z axis
             targetRotation.x = 0.0f;
             targetRotation.z = 0.0f;
 
             float t = runningTime / Duration;
 
             thing.transform.rotation = Quaternion.Slerp(initialRotation, targetRotation, t);


Comment
Add comment · Show 1 · 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
avatar image Harinezumi · Mar 07, 2018 at 12:18 PM 0
Share

Yes, this approach (although a bit specific) will work. I think I did something similar, or turned off the FirstPersonController when I wanted direct control.

Follow this Question

Answers Answers and Comments

61 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 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 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 avatar image avatar image avatar image avatar image

Related Questions

Mouse Look Controller that can rotate on the Z axis 1 Answer

How to apply a deadzone to camera for mouse position on Unity's default FPC? 0 Answers

Storing Position of First Person Camera 1 Answer

AddForce to mouse? 0 Answers

How do i make camera movement smoother? 1 Answer


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