回答編集履歴

3

詳細の追加とコードの修正

2020/08/07 14:26

投稿

hehebeb
hehebeb

スコア728

test CHANGED
@@ -1 +1,75 @@
1
1
  完成を止めたい瞬間に[`Rigidbody.velocity = Vector3.zero`](https://mogi0506.com/unity-rigidbody-stop/)を実行。
2
+
3
+
4
+
5
+ 質問者様の場合、
6
+
7
+ ```C#
8
+
9
+ using System.Collections;
10
+
11
+ using System.Collections.Generic;
12
+
13
+ using UnityEngine;
14
+
15
+
16
+
17
+ public class PlayerController : MonoBehaviour
18
+
19
+ {
20
+
21
+ Rigidbody2D rigid;
22
+
23
+ public float walkForce = 15.0f;
24
+
25
+ private Vector2 inputAxis;
26
+
27
+
28
+
29
+ private void Start()
30
+
31
+ {
32
+
33
+ this.rigid = GetComponent<Rigidbody2D>();
34
+
35
+ }
36
+
37
+
38
+
39
+ private void Update()
40
+
41
+ {
42
+
43
+ inputAxis.x = Input.GetAxis("Horizontal");
44
+
45
+ inputAxis.y = Input.GetAxis("Vertical");
46
+
47
+
48
+
49
+ if(Input.GetKeyUp(KeyCode.W) || Input.GetKeyUp(KeyCode.S) || Input.GetKeyUp(KeyCode.A) || Input.GetKeyUp(KeyCode.D))
50
+
51
+ {
52
+
53
+ rigid.velocity = Vector2.zero;
54
+
55
+ }
56
+
57
+ }
58
+
59
+
60
+
61
+ private void FixedUpdate()
62
+
63
+ {
64
+
65
+ rigid.velocity = inputAxis.normalized * walkForce;
66
+
67
+ }
68
+
69
+
70
+
71
+
72
+
73
+ }
74
+
75
+ ```

2

詳細の追加とコードの修正

2020/08/07 14:26

投稿

hehebeb
hehebeb

スコア728

test CHANGED
@@ -1 +1 @@
1
- [Rigidbody.velocity = Vector3.zero](https://mogi0506.com/unity-rigidbody-stop/)
1
+ 完成を止めたい瞬間に[`Rigidbody.velocity = Vector3.zero`](https://mogi0506.com/unity-rigidbody-stop/)を実行。

1

コードの修正

2020/08/07 14:13

投稿

hehebeb
hehebeb

スコア728

test CHANGED
@@ -1,3 +1 @@
1
- [Rigidbody.velocity = Vector3.zero;
2
-
3
- ](https://mogi0506.com/unity-rigidbody-stop/)
1
+ [Rigidbody.velocity = Vector3.zero](https://mogi0506.com/unity-rigidbody-stop/)