質問編集履歴
1
文章を最適化しました。
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
|
1
|
+
velocityでyの値を変更する時と変更しない場合で移動速度が変わる原因とは?
|
body
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
-
/////////////
|
1
|
+
提示コード「/////////////ここのコードです。」
|
2
|
-
|
2
|
+
質問 なのですがなぜ移動できなくなるのでしょうか?毎フレームgrivity_forceの値を-10ずつ加算したいのでそうすると移動できず固定されてしまいます。
|
3
3
|
|
4
|
+
※また new vector3(0,gravity_force,0);の加算処理を無くすと移動速度がwalk_speedの値を思われる正常の値?で移動されます。
|
4
5
|
|
5
6
|
|
7
|
+
|
8
|
+
|
6
9
|
```ここに言語を入力
|
7
10
|
using System.Collections;
|
8
11
|
using System.Collections.Generic;
|
@@ -19,13 +22,14 @@
|
|
19
22
|
/*調整量関係*/
|
20
23
|
|
21
24
|
private float gravity_force = -10.0f;
|
22
|
-
private const float walk_speed =
|
25
|
+
private const float walk_speed = 20.0f;//移動速度
|
23
26
|
private const float jump_force = 40.00f;
|
24
27
|
|
25
28
|
|
26
29
|
/*状態判定 系*/
|
27
30
|
private bool isJump;
|
28
31
|
private bool isGround;
|
32
|
+
|
29
33
|
// Use this for initialization
|
30
34
|
void Start()
|
31
35
|
{
|
@@ -46,7 +50,7 @@
|
|
46
50
|
input_v = Input.GetAxis("Vertical");
|
47
51
|
Vector3 move_x = new Vector3();
|
48
52
|
Vector3 move_z = new Vector3();
|
49
|
-
|
53
|
+
//Vector3 move_y = new Vector3(0,-10.0f,0);
|
50
54
|
move_z = Vector3.Scale(Camera.main.transform.forward, new Vector3(1, 0, 1)).normalized * input_v * walk_speed;
|
51
55
|
move_x = Camera.main.transform.right * input_h * walk_speed;
|
52
56
|
move = move_x + move_z;
|
@@ -56,35 +60,11 @@
|
|
56
60
|
transform.rotation = Quaternion.LookRotation(v.normalized);
|
57
61
|
}
|
58
62
|
|
63
|
+
gravity_force += -10.0f;
|
64
|
+
rb.velocity = move + new Vector3(0,gravity_force,0);///////////ここのコードです。
|
65
|
+
//rb.velocity = move;
|
59
66
|
|
60
|
-
/*ジャンプ処理*/
|
61
|
-
if (Input.GetKey(KeyCode.Space))
|
62
|
-
{
|
63
|
-
isJump = true;
|
64
|
-
}
|
65
|
-
|
66
|
-
if (isJump == true)
|
67
|
-
{
|
68
|
-
// rb.AddForce(new Vector3(0,jump_force,0));
|
69
|
-
isJump = false;
|
70
|
-
}
|
71
|
-
else
|
72
|
-
{
|
73
|
-
|
74
|
-
|
67
|
+
Debug.Log(rb.velocity);
|
75
|
-
}
|
76
|
-
|
77
|
-
if (isGround == false)
|
78
|
-
{
|
79
|
-
// gravity_force += -10.0f;
|
80
|
-
// rb.AddForce(rb.velocity.x, gravity_force, rb.velocity.z);
|
81
|
-
}
|
82
|
-
|
83
|
-
//gravity_force += -10.0f;
|
84
|
-
rb.AddForce(rb.velocity.x, gravity_force, rb.velocity.z);//////////////////////
|
85
|
-
|
86
|
-
|
87
|
-
rb.velocity = move;//////////////////
|
88
68
|
}
|
89
69
|
|
90
70
|
/*移動*/
|
@@ -111,7 +91,11 @@
|
|
111
91
|
{
|
112
92
|
isGround = true;
|
113
93
|
isJump = false;
|
94
|
+
|
95
|
+
// gravity_force = 0;
|
96
|
+
rb.velocity = new Vector3(0,0,0);
|
97
|
+
// rb.velocity = new Vector3(rb.velocity.x, 0, rb.velocity.z);
|
114
|
-
rb.velocity = new Vector3(rb.velocity.x, 0, rb.velocity.z);
|
98
|
+
//rb.velocity = new Vector3(rb.velocity.x, 0, rb.velocity.z);
|
115
99
|
}
|
116
100
|
}
|
117
101
|
|