2017-04-18 6 views
0

標準アセットからFreeLookCamスクリプトを調整して、私のゲームで動作させようとしていますが、これは標準的なユニティプロジェクトとは異なる "ワールドアップ"です。私の場合は、ワールドアップは-zです。このシナリオに合わせてスクリプトを調整することはできません。ここで別の "world up"のFreeLookCamスクリプト?

は、私はそれをしようとすると、それがどのように見えるかです:https://www.youtube.com/watch?v=Ppb-tXvLZpI

、ここではコードです:

using System; 
using UnityEngine; 
//using UnityStandardAssets.CrossPlatformInput; 

namespace UnityStandardAssets.Cameras 
{ 
    public class FreeLookCam : PivotBasedCameraRig 
    { 
     // This script is designed to be placed on the root object of a camera rig, 
     // comprising 3 gameobjects, each parented to the next: 

     // Camera Rig 
     //  Pivot 
     //   Camera 

     [SerializeField] private float m_MoveSpeed = 1f;      // How fast the rig will move to keep up with the target's position. 
     [Range(0f, 10f)] [SerializeField] private float m_TurnSpeed = 1.5f; // How fast the rig will rotate from user input. 
     [SerializeField] private float m_TurnSmoothing = 0.0f;    // How much smoothing to apply to the turn input, to reduce mouse-turn jerkiness 
     [SerializeField] private float m_TiltMax = 75f;      // The maximum value of the x axis rotation of the pivot. 
     [SerializeField] private float m_TiltMin = 45f;      // The minimum value of the x axis rotation of the pivot. 
     [SerializeField] private bool m_LockCursor = false;     // Whether the cursor should be hidden and locked. 
     [SerializeField] private bool m_VerticalAutoReturn = false;   // set wether or not the vertical axis should auto return 

     private float m_LookAngle;     // The rig's y axis rotation. 
     private float m_TiltAngle;     // The pivot's x axis rotation. 
     private const float k_LookDistance = 100f; // How far in front of the pivot the character's look target is. 
     private Vector3 m_PivotEulers; 
     private Quaternion m_PivotTargetRot; 
     private Quaternion m_TransformTargetRot; 

     protected override void Awake() 
     { 
      base.Awake(); 
      // Lock or unlock the cursor. 
      Cursor.lockState = m_LockCursor ? CursorLockMode.Locked : CursorLockMode.None; 
      Cursor.visible = !m_LockCursor; 
      m_PivotEulers = m_Pivot.rotation.eulerAngles; 

      m_PivotTargetRot = m_Pivot.transform.localRotation; 
      m_TransformTargetRot = transform.localRotation; 
     } 


     protected void Update() 
     { 
      HandleRotationMovement(); 
      if (m_LockCursor && Input.GetMouseButtonUp(0)) 
      { 
       Cursor.lockState = m_LockCursor ? CursorLockMode.Locked : CursorLockMode.None; 
       Cursor.visible = !m_LockCursor; 
      } 
     } 


     private void OnDisable() 
     { 
      Cursor.lockState = CursorLockMode.None; 
      Cursor.visible = true; 
     } 


     protected override void FollowTarget(float deltaTime) 
     { 
      if (m_Target == null) return; 
      // Move the rig towards target position. 
      transform.position = Vector3.Lerp(transform.position, m_Target.position, deltaTime*m_MoveSpeed); 
     } 


     private void HandleRotationMovement() 
     { 
      if(Time.timeScale < float.Epsilon) 
      return; 

      // Read the user input 
//   var x = CrossPlatformInputManager.GetAxis("Mouse X"); 
//   var y = CrossPlatformInputManager.GetAxis("Mouse Y"); 
      var x = Input.GetAxis("Mouse X"); 
      var y = Input.GetAxis("Mouse Y"); 

      // Adjust the look angle by an amount proportional to the turn speed and horizontal input. 
      m_LookAngle += x*m_TurnSpeed; 

      // Rotate the rig (the root object) around Y axis only: 
      m_TransformTargetRot = Quaternion.Euler(0f, m_LookAngle, 0f); 

      if (m_VerticalAutoReturn) 
      { 
       // For tilt input, we need to behave differently depending on whether we're using mouse or touch input: 
       // on mobile, vertical input is directly mapped to tilt value, so it springs back automatically when the look input is released 
       // we have to test whether above or below zero because we want to auto-return to zero even if min and max are not symmetrical. 
       m_TiltAngle = y > 0 ? Mathf.Lerp(0, -m_TiltMin, y) : Mathf.Lerp(0, m_TiltMax, -y); 
      } 
      else 
      { 
       // on platforms with a mouse, we adjust the current angle based on Y mouse input and turn speed 
       m_TiltAngle -= y*m_TurnSpeed; 
       // and make sure the new value is within the tilt range 
       m_TiltAngle = Mathf.Clamp(m_TiltAngle, -m_TiltMin, m_TiltMax); 
      } 

      // Tilt input around X is applied to the pivot (the child of this object) 
//   m_PivotTargetRot = Quaternion.Euler(m_TiltAngle, m_PivotEulers.y , m_PivotEulers.z); 
      m_PivotTargetRot = Quaternion.Euler(m_TiltAngle, m_PivotEulers.y , m_PivotEulers.z); 


      if (m_TurnSmoothing > 0) 
      { 
       m_Pivot.localRotation = Quaternion.Slerp(m_Pivot.localRotation, m_PivotTargetRot, m_TurnSmoothing * Time.deltaTime); 
       transform.localRotation = Quaternion.Slerp(transform.localRotation, m_TransformTargetRot, m_TurnSmoothing * Time.deltaTime); 
      } 
      else 
      { 
       m_Pivot.localRotation = m_PivotTargetRot; 
       transform.localRotation = m_TransformTargetRot; 
      } 
     } 
    } 
} 
+0

あなたの質問には関係ありませんが、ワールドアップを使用していない場合は、カメラアダプテーションスクリプト以外の問題が反映されます。 剛体と粒子の重力を手動で適用する必要があります(これは単なる追加作業であり、解決できません)、粒子の掲示板は望ましくない方法で回転します。 –

答えて

0

あり、両方HandleRotationMovementで変更する必要がある2行は、であり、それらの両方を持っていますyとzの角度を入れ替えることに関係します。最初のものは、ライン83上にある:

// Rotate the rig (the root object) around Y axis only: 
m_TransformTargetRot = Quaternion.Euler(0f, 0f, m_LookAngle); 

2つ目は、ライン101上にある:私は、予想される範囲内の傾きの制限を取得するために90度を追加しなければならなかった、第2行目に

// Tilt input around X is applied to the pivot (the child of this object) 
m_PivotTargetRot = Quaternion.Euler(m_TiltAngle + 90, m_PivotEulers.z , m_PivotEulers.y); 

yとzの角度を入れ替えるだけでなく、