teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

文章を最適化しました。

2019/09/29 01:35

投稿

退会済みユーザー
title CHANGED
@@ -1,1 +1,1 @@
1
- AddForceとvelocityを使うと落下後操作きなくなが少ている原因が知りたい
1
+ velocityでyの値を変更す時と変更場合で移動速度が変わる原因とは?
body CHANGED
@@ -1,8 +1,11 @@
1
- /////////////コメント部のコードなのですがなぜ移動できなくなるのでしょうか? 移動はvelocityの方が操作しやすく重量とジャンプは
1
+ 提示コード「/////////////ここのコードです。」
2
- AddForceわりに合うのでそうています。また毎フレームgrivity_forceの値を-10ずつ加算したいのでそうすると移動できず固定されてしまいます。
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 = 40.0f;//移動速度
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
- // Debug.Log(move_y.y);
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