質問内容
質問ですがどうやって移動可能でまたJump()関数のアニメーションを実行できる処理が実装出来るのでしょうか?
試したこと
提示コードのvoid Update() ,void LateUpdate()
部ですがMove(),Jump()
関数の順序を入れて変えてましたが移動は出来るのですがJump()
のアニメーションが実行されない。逆にするとJump()
関数のアニメーションが実行されるが動かせないバグが発生します。二つともLateUpdate()に置いても同じでした。
※idleには何もアタッチされておらすjumpにはトリガーでjumpに移りアニメーション(positoin.yが加算されて減算される処理)が実行されることになっています。
参考サイト:
https://docs.unity3d.com/ja/2018.4/ScriptReference/MonoBehaviour.LateUpdate.htm
参考サイト:
Player.cs
cs
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5namespace Player 6{ 7 8 /* 9 * ################################################# 10 * プレイヤーコントロール 11 * ################################################# 12 */ 13 14 public class Player_Control : MonoBehaviour 15 { 16 17 [SerializeField] const float walkSpeed = 10; //移動速度 18 [SerializeField] const float fallSpeed = 15; //落下速度 19 [SerializeField] GameObject weapon; //武器 20 private Vector3 moveSpeed; 21 22 private CharacterController controller; 23 private Animator animator; 24 25 26 void Start() 27 { 28 controller = GetComponent<CharacterController>(); 29 animator = GetComponent<Animator>(); 30 } 31 32 void Update() 33 { 34 //Move(); 35 Jump(); 36 } 37 38 void LateUpdate() 39 { 40 //Jump(); 41 Move(); 42 43 } 44 45 46 47 /*########################################## 移動 ##########################################*/ 48 private void Move() 49 { 50 float inputHorizontal = Input.GetAxis("Left_Horizontal"); 51 float inputVertical = Input.GetAxis("Left_Vertical"); 52 53 Quaternion horizontalRotation = Quaternion.AngleAxis(Camera.main.transform.eulerAngles.y,Vector3.up); 54 Vector3 velocity = horizontalRotation * new Vector3(inputHorizontal, 0, inputVertical * -1).normalized; 55 56 if (velocity.magnitude > 0.3f) 57 { 58 transform.rotation = Quaternion.LookRotation(velocity, transform.up); 59 moveSpeed.x = (velocity * walkSpeed).x; 60 moveSpeed.z = (velocity * walkSpeed).z; 61 62 } 63 else 64 { 65 moveSpeed.x = 0; 66 moveSpeed.z = 0; 67 } 68 69 moveSpeed.y = 0; 70 //moveSpeed.y = -20; //落下重力 71 72 73 Vector3 move = Vector3.Scale(moveSpeed, new Vector3(1, 0, 1)); 74 controller.Move(moveSpeed * Time.deltaTime); //移動 75 76 77 78 } 79 80 81 /*########################################## 攻撃 ##########################################*/ 82 private void Attack() 83 { 84 85 } 86 87 /*########################################## ジャンプ ##########################################*/ 88 private void Jump() 89 { 90 if(Input.GetButtonDown("Cross") == true) 91 { 92 Debug.Log("ああああ"); 93 animator.SetTrigger("Jump"); 94 } 95 } 96 97 98 99 } 100
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2022/04/11 01:10
2022/04/11 01:32