前提・実現したいこと
unityで3Dシューティングゲームを作っています。
カメラで自機を追尾するプログラムを作成しているのですが、
Quaternion.Slerpを使った場合においての角度制限のつけ方が分かりません。
制限を付けたい方向はX軸です。
どうかご教授いただけると幸いでございます。
該当のソースコード
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class CameraControl : MonoBehaviour { 6 Transform cameraTrans; 7 [SerializeField] Transform playerTrans; 8 [SerializeField] Vector3 cameraVec; 9 [SerializeField] Vector3 cameraRot; 10 [SerializeField] readonly float speed = 10f; 11 12 void Awake() 13 { 14 cameraTrans = transform; 15 cameraTrans.rotation = Quaternion.Euler(cameraRot); 16 } 17 void Update() 18 { 19 Vector3 diffPos = playerTrans.position - transform.position; 20 float step = speed * Time.deltaTime; 21 cameraTrans.position = Vector3.Lerp(cameraTrans.position, playerTrans.position + cameraVec, 12.5f * Time.deltaTime); 22 cameraTrans.rotation = Quaternion.Slerp(cameraTrans.rotation, Quaternion.LookRotation(diffPos), step); 23 } 24}
補足情報
UnityのバージョンはUnity2018.3.0.f2で
C#はvisual studioを使用
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/12/18 04:01