提示コードですがこの武器が上下にふわふわアニメーションしてましてカメラが左を向くと武器もプレイヤーを中心に左に回転するという処理を実現したいです。スクリプトで左右に回転するコードを組みましたが上手く実装出来ません。
cs
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class WeaponControl : MonoBehaviour 6{ 7 public GameObject player; 8 public GameObject camera; 9 [SerializeField] float rotateSpeed = 600; 10 [SerializeField] float orbitSpeed = 600; 11 [SerializeField] float Y_distance = 2; 12 [SerializeField] float distance = 3; 13 14 15 16// public GameObject camera; 17 private Animator animator; 18 // Start is called before the first frame update 19 void Start() 20 { 21 animator = GetComponent<Animator>(); 22 } 23 24 25 26 27 float timeCount = 0f; 28 29 // Update is called once per frame 30 void Update() 31 { 32 33 Orbit(); //武器軌道 34 35 36 Orbit_Animation(); //武器 切り替え 37 } 38 39 40 41 42 43 44 45 /*########################################## 武器 回転 ##########################################*/ 46 private void Orbit() 47 { 48 if (animator.GetCurrentAnimatorStateInfo(0).IsName("Idle") == true) 49 { 50 51 Quaternion q = Quaternion.Euler(transform.forward); 52 Vector3 p = Vector3.Normalize(player.transform.position - camera.transform.position) * distance; 53 54 Vector3 pDash = q * p; 55 56 transform.position = pDash; 57 } 58 } 59 60 61 62 /*########################################## 武器 切り替え ##########################################*/ 63 private void Orbit_Animation() 64 { 65 66 if (animator.GetCurrentAnimatorStateInfo(0).IsName("Orbit") == true) 67 { 68 transform.RotateAround(player.transform.position, Vector3.up, orbitSpeed * Time.deltaTime); 69 } 70 } 71} 72
回答1件
あなたの回答
tips
プレビュー