提示コードですがモンハン等であるプレイヤーを中心にカメラが回転して追尾する処理ですが以下はcinemachine free look cameraで実装しようとしているのですがプレイヤーが動くとその方向にカメラが回転してします。自分は回転キーを押した時回転してほしいのでプレイヤーが動いてもその方向には回転してほしくないのですが。それをするにはどうしたらいいのでしょうか?下記のスクリプトを実装しましたが上手く実装できません。
CameraControl.cs
cs
1using System.Collections; 2using System.Collections.Generic; 3using Cinemachine; 4using UnityEngine; 5 6public class CameraControl : MonoBehaviour 7{ 8 public GameObject player; 9 //public CinemachineVirtualCamera camera; 10 [SerializeField] const float rotateSpeed = 5; //回転速度 11 12 private Vector3 offset; //プレイヤーとの距離 13 14 void Start() 15 { 16 17 } 18 19 void Update() 20 { 21 Rotate(); //カメラ回転 22 } 23 24 void LateUpdate() 25 { 26 27 } 28 29 /*########################################## 回転 ##########################################*/ 30 private void Rotate() 31 { 32 float inputHorizontal = Input.GetAxis("Right_Horizontal"); 33 float inputVertical = 0; 34 //float inputVertical = Input.GetAxis("Right_Vertical"); 35 36 37 Vector3 angle = new Vector3(inputHorizontal, inputVertical,0 ); 38 39 if(angle.magnitude > 0.1) 40 { 41 GetComponent<CinemachineVirtualCamera>().GetCinemachineComponent<CinemachineOrbitalTransposer>().m_Heading.m_Bias += inputHorizontal * rotateSpeed; //Biasを操作 42 //GetComponent<CinemachineVirtualCamera>().GetCinemachineComponent<CinemachineOrbitalTransposer>().m_FollowOffset.y -= inputVertical * rotateSpeed / 2; //Biasを操作 43 transform.RotateAround(player.transform.position, Vector3.up, inputHorizontal * rotateSpeed); 44 //transform.RotateAround(player.transform.position, transform.right, inputVertical * rotateSpeed); 45 } 46 } 47} 48
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2022/03/20 03:11