c# - Unity Player Controller - how to make it so it doesn't go upside down -


this cammouselook script , need when player moves mouse way doesnt turn upside down. want him able not turns view upside down

using system.collections; using system.collections.generic; using unityengine;  public class cammouselook : monobehaviour {      vector2 mouselook;     vector2 smoothv;     public float sensitivity = 5.0f;     public float smoothing = 2.0f;      gameobject character;      // use initialization     void start () {         character = this.transform.parent.gameobject;        }      // update called once per frame     void update () {         var md = new vector2(input.getaxisraw("mouse x"), input.getaxisraw("mouse y"));          md = vector2.scale(md, new vector2(sensitivity * smoothing, sensitivity * smoothing));         smoothv.x = mathf.lerp(smoothv.x, md.x, 1f / smoothing);         smoothv.y = mathf.lerp(smoothv.y, md.y, 1f / smoothing);         mouselook += smoothv;          transform.localrotation = quaternion.angleaxis(-mouselook.y, vector3.right);         character.transform.localrotation = quaternion.angleaxis(mouselook.x, character.transform.up);     } } 

what can lock rotation in specific axis. example limit in y , x axis player can rotate [-60,60] degrees can use:

using system; using unityengine;  public class mouselook : monobehaviour {     public float mousesensitivity = 70.0f;     public float clampangle = 60.0f;      private float roty = 0.0f; // rotation around up/y axis     private float rotx = 0.0f; // rotation around right/x axis      void start ()     {         vector3 rot = transform.localrotation.eulerangles;         roty = rot.y;         rotx = rot.x;     }      void update ()     {         float mousex = input.getaxis("mouse x");         float mousey = -input.getaxis("mouse y");          roty += mousex * mousesensitivity * time.deltatime;         rotx += mousey * mousesensitivity * time.deltatime;          rotx = mathf.clamp(rotx, -clampangle, clampangle);          quaternion localrotation = quaternion.euler(rotx, roty, 0.0f);         transform.rotation = localrotation;     } } 

now can adapt script limit rotation in angle , range need


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -