質問編集履歴
1
文章の具体性を増しました。スクリプトを追加しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,4 +1,42 @@
|
|
1
1
|
### 前提・実現したいこと
|
2
2
|
|
3
3
|
UnityではスタンダードアセットのThirdPersonUserControlを3Dモデルにアタッチすることで移動やジャンプができるようになりますよね。
|
4
|
+
そこで質問なのですが、このスクリプトではジャンプ中に移動をすることができません。(ジャンプ中は矢印キーが効かない)
|
4
|
-
|
5
|
+
なので、これを書き換えて、ジャンプ中でも移動できるようにしたいです。(3Dマリオのような感じで、ジャンプ中でも方向移動ができるようにしたいです)Webサイトで調べても出てこず困っています。方法を教えてください。
|
6
|
+
|
7
|
+
### 試したこと
|
8
|
+
|
9
|
+
接地判定に関わっていそうな箇所を消したりしてみたのですが、うまくいきませんでした。
|
10
|
+
スクリプトはアセットストアから無料で入手できる、スタンダードアセットに入っているThirdPersonUserControlとThirdPersonCharacterというスクリプトです。全文は字数の関係で載せられませんでしたが、以下、ThirdPersonCharacter
|
11
|
+
スクリプトの一部を載せておきます。このあたりが怪しいと思うのですが。。。
|
12
|
+
|
13
|
+
```C#
|
14
|
+
void HandleGroundedMovement(bool crouch, bool jump)
|
15
|
+
{
|
16
|
+
// check whether conditions are right to allow a jump:
|
17
|
+
if (jump && !crouch && m_Animator.GetCurrentAnimatorStateInfo(0).IsName("Grounded"))
|
18
|
+
{
|
19
|
+
// jump!
|
20
|
+
m_Rigidbody.velocity = new Vector3(m_Rigidbody.velocity.x, m_JumpPower, m_Rigidbody.velocity.z);
|
21
|
+
m_IsGrounded = false;
|
22
|
+
m_Animator.applyRootMotion = false;
|
23
|
+
m_GroundCheckDistance = 0.1f;
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
public void OnAnimatorMove()
|
28
|
+
{
|
29
|
+
// we implement this function to override the default root motion.
|
30
|
+
// this allows us to modify the positional speed before it's applied.
|
31
|
+
//条件無くすとジャンプ中止まる
|
32
|
+
if (m_IsGrounded && Time.deltaTime > 0)
|
33
|
+
{
|
34
|
+
//移動するのに必要な部分!!
|
35
|
+
Vector3 v = (m_Animator.deltaPosition * m_MoveSpeedMultiplier) / Time.deltaTime;
|
36
|
+
|
37
|
+
//we preserve the existing y part of the current velocity.
|
38
|
+
v.y = m_Rigidbody.velocity.y;
|
39
|
+
m_Rigidbody.velocity = v;
|
40
|
+
}
|
41
|
+
}
|
42
|
+
```
|