質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Unity3D

Unity3Dは、ゲームや対話式の3Dアプリケーション、トレーニングシュミレーション、そして医学的・建築学的な技術を可視化する、商業用の開発プラットフォームです。

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

Q&A

解決済

1回答

835閲覧

Unityでの着地判定(CharacterControllerを使用)をとってJumpアニメーションを途中で切る方法

退会済みユーザー

退会済みユーザー

総合スコア0

C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Unity3D

Unity3Dは、ゲームや対話式の3Dアプリケーション、トレーニングシュミレーション、そして医学的・建築学的な技術を可視化する、商業用の開発プラットフォームです。

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

0グッド

0クリップ

投稿2019/11/24 17:06

編集2019/11/25 06:43

現在UnityとC#で3Dアクションゲームを作っています。CharacterControllerを使ってキャラを動かしているのですが、ジャンプの開始の際にCharacterControllerのisGround=trueを使ってしまっているのでジャンプ後の着地をどうとればいいかわかりません。
(CharacterAnimationスクリプト内のInputButtonのif(isGround)でジャンプをしているが同じisGround内でanim.SetBool("jump",false)と書いてしまうとジャンプアニメーションが再生されないため)
Unityでキャラクターがジャンプ出来るようにするこちらの記事は拝見済みです。
この方法がわかればアニメーションを途中で切ることはできます。
よろしくお願いします。

using

1using System.Collections.Generic; 2using UnityEngine; 3 4public class DS4InputManager : MonoBehaviour { 5 6 protected float Rx, Ry, Lx, Ly =0; 7 8 protected virtual void Update() 9 { 10 InputJoysticks(); 11 if (Input.anyKeyDown) 12 { 13 InputButton(); 14 } 15 } 16 17 protected virtual void InputJoysticks() 18 { 19 Rx = Input.GetAxisRaw("Horizontal"); 20 Ry = Input.GetAxisRaw("Vertical"); 21 Lx = Input.GetAxis("LHorizontal"); 22 Ly = Input.GetAxis("LVertical"); 23 24 Debug.Log("右(" + (int)Rx + "," + (int)Ry+")"); 25 Debug.Log("左(" + (int)Lx + "," + (int)Ly + ")"); 26 } 27 28 protected virtual void InputButton() 29 { 30 31 if (Input.GetButtonDown("DS4x")) 32 { 33 Debug.Log("x(space)を押しました。"); 34 } 35 if (Input.GetButtonDown("DS4o")) 36 { 37 Debug.Log("o(enter)を押しました。"); 38 } 39 //追加があればこの下に追加 40 //if (Input.GetButtonDown("")) 41 //{ 42 43 //} 44 45 } 46} 47 48

using

1using System.Collections.Generic; 2using UnityEngine; 3 4public class CharacterActionManager : DS4InputManager { 5 6 private CharacterController C_controller; 7 [SerializeField] 8 private float movespeed; 9 [SerializeField] 10 private float jumppower; 11 private CharacterAnimation C_Animation; 12 private Vector2 direction; 13 private Vector2 jumpdirection; 14 15 private void Start() 16 { 17 C_controller = gameObject.GetComponent<CharacterController>(); 18 C_Animation = gameObject.GetComponent<CharacterAnimation>(); 19 } 20 21 protected override void Update() 22 { 23 base.Update(); 24 GroundedCheck(); 25 CharacterMove(); 26 } 27 28 protected override void InputJoysticks() 29 { 30 base.InputJoysticks(); 31 Debug.Log(Lx); 32 if (Lx != 0) 33 { 34 35 CharacterdirectionChange(Lx); 36 37 Lx = Lx * movespeed; 38 direction = new Vector2(Lx, 0); 39 40 } 41 else 42 { 43 direction = new Vector2(0, 0); 44 } 45 } 46 47 protected override void InputButton() 48 { 49 base.InputButton(); 50 51 if (C_controller.isGrounded) 52 { 53 if (Input.GetButtonDown("DS4x")) 54 { 55 jumpdirection.y = jumppower; 56 57 } 58 } 59 60 61 } 62 63 private void CharacterMove() 64 { 65 66 jumpdirection.y -= jumppower*2* Time.deltaTime; 67 direction = direction + jumpdirection; 68 C_controller.Move(direction* Time.deltaTime); 69 } 70 71 private void GroundedCheck() 72 { 73 if (!C_controller.isGrounded) 74 { 75 Debug.DrawLine(gameObject.transform.position, gameObject.transform.position - gameObject.transform.up,Color.green) ; 76 if (Physics.Linecast(gameObject.transform.position, gameObject.transform.position-gameObject.transform.up)) 77 { 78 C_Animation.isGround = true; 79 } 80 else 81 { 82 C_Animation.isGround = false; 83 } 84 } 85 86 if (C_controller.isGrounded) 87 { 88 C_Animation.isGround = true; 89 } 90 91 } 92 93 94 private void CharacterdirectionChange(double direction) 95 { 96 Vector3 Angle = gameObject.transform.localEulerAngles; 97 if (direction == 0) return; 98 if (direction > 0) 99 { 100 Angle.y = 90f; 101 } 102 if(direction<0) 103 { 104 Angle.y= -90f; 105 } 106 107 gameObject.transform.localEulerAngles = Angle; 108 } 109 110 111} 112 113

using

1using System.Collections.Generic; 2using UnityEngine; 3 4public class CharacterAnimation : DS4InputManager 5{ 6 7 private Animator anim; 8 private bool cananim; 9 private bool stop; 10 public bool isGround; 11 public bool landground; 12 13 14 private void Start() 15 { 16 anim = gameObject.GetComponent<Animator>(); 17 cananim = false; 18 stop = false; 19 isGround = false; 20 landground = true; 21 } 22 23 protected override void InputJoysticks() 24 { 25 base.InputJoysticks(); 26 27 if (Lx != 0) 28 { 29 if (!anim.GetCurrentAnimatorStateInfo(0).IsName("jump")) 30 { 31 anim.SetBool("run", true); 32 } 33 } 34 else 35 { 36 37 anim.SetBool("run", false); 38 } 39 } 40 41 protected override void InputButton() 42 { 43 base.InputButton(); 44 45 if (!stop) 46 { 47 if (Input.GetButtonDown("DS4o")) 48 { 49 anim.SetTrigger("skill" + 1); 50 Debug.Log("skill" + 1); 51 } 52 } 53 54 if (isGround) 55 { 56 if (Input.GetButtonDown("DS4x")) 57 { 58 59 anim.SetBool("jump", true); 60 Debug.Log("JUMP"); 61 62 } 63 anim.SetBool("jump", false); 64 } 65 66 67 68 } 69 70}

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

sakura_hana

2019/11/25 02:01

「着地をどうとればいいか」の意味が分かりません。 if (isGround) { 〜省略〜 } else { anim.SetBool("jump", false); } ではダメなのでしょうか?
退会済みユーザー

退会済みユーザー

2019/11/25 06:47

そうするとjumpアニメーション中にスティックの入力があった際にrunアニメーションに切り替わってしまうので、ジャンプ後に着地するまでjumpアニメーションをし続け着地したらrunアニメーションに切り替わるというふうにしたいです。
sakura_hana

2019/11/25 08:28

であれば「ジャンプ中」を示すフラグ(変数)を追加すればいいかと思います。
退会済みユーザー

退会済みユーザー

2019/11/25 09:32

うまくいきました。ありがとうございます。
guest

回答1

0

ベストアンサー

update内でフラグをtrue、jumpアニメーション時にフラグをfalseにしアニメーション遷移の時間を調整することで違和感なくアニメーション遷移できるようになりました

投稿2019/11/25 09:32

退会済みユーザー

退会済みユーザー

総合スコア0

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問