2017-09-10 3 views
0

이것은 내 CamMouseLook 스크립트이며, 플레이어가 마우스를 완전히 위로 움직이면 거꾸로 뒤집습니다. 이 특정 축에서 회전을 잠그는 것입니다 거꾸로Unity Player Controller - 거꾸로되지 않도록 만드는 방법

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 this for initialization 
    void Start() { 
     character = this.transform.parent.gameObject; 
    } 

    // Update is 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); 
    } 
} 

답변

0

할 수있는 일보기를 켜지는지 나는 그를 그냥 순전히을 찾아 볼 수 있어야합니다. 플레이어에서 회전 만 할 수 있도록 예제는 Y와 X 축에서 제한하려면 [-60,60]를 사용할 수있는 학위 :

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 the up/y axis 
    private float rotX = 0.0f; // rotation around the 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; 
    } 
} 

지금 당신은 각도와의 회전을 제한하려면이 스크립트를 적용 할 수 있습니다 필요한 범위

+0

나는 당신을 사랑합니다. thnx fam –