Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Unity 5 FPS-Controller: rotate Player

Discussion in 'Scripting' started by RedFireBlitz, Mar 11, 2015.

  1. RedFireBlitz

    RedFireBlitz

    Joined:
    Feb 18, 2015
    Posts:
    3
    Hey guys

    at the moment iam trying to implement the new FPS Controller from the Unity 5 Standard Assest

    in my Game is a Collider that sets the player rotation to 0,270,0 so the player is looking automaticly in the right direction. the code for this is simple:

    Code (CSharp):
    1. other.transform.rotation = tp.transform.rotation;
    tp.transform.rotation is an object that has the rotation 0,270,0

    But it doenst work with the new FPS Controller, probably because of the mouselook script.

    has anyone an idea how to change my look direction with the new FPS Controller ?
     
  2. ZefanS

    ZefanS

    Joined:
    Jun 22, 2015
    Posts:
    18
    I've been having the same problem. So far everything I've tried has no result. It seems like any changes you make just get overwritten by the mouselook script.
     
  3. Robdon

    Robdon

    Joined:
    Jan 10, 2014
    Posts:
    141
    I've been getting the same problem, and yes its because the mouselook script it holding the current rotation for the controller and camera, and then only applies the mouse movement to it, therefore it doesnt know about any modification from the outside.

    I currently dont have the time to write my own Controller, but that would be the best thing, so I came up with a quick fix:

    Edit FirstPersonController.cs that comes with FPS Controller, and add the following function just below the Start() function

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

    Then back in your code, once you have changed the rotation, immediately call this new function to reset the position to your new one. Something like this:

    other.transform.rotation= tp.transform.rotation;
    other.GetComponent<FirstPersonController>().mouseReset();


    HTHs
     
  4. RPKMN1

    RPKMN1

    Joined:
    Feb 13, 2017
    Posts:
    34
    sorry to necro this post but... pulled my hair out for half an hour trying to figure this out. thanks!
     
  5. vinay_vidhani

    vinay_vidhani

    Joined:
    Oct 27, 2016
    Posts:
    10
    Thank you so much, you made my day, I love man.... :)
     
    Robdon likes this.