質問編集履歴

1

文章を編集

2019/10/12 11:51

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -2,7 +2,13 @@
2
2
 
3
3
 
4
4
 
5
-
5
+ 法線ベクトルを使って見舞いしたが変わりません。
6
+
7
+
8
+
9
+
10
+
11
+ ※参考サイト: http://nnana-gamedev.hatenablog.com/entry/2017/12/19/223948#Vector3ProjectOnPlaneVector3-vector-Vector3-planeNormal%E3%82%92%E4%BD%BF%E3%81%86%E6%96%B9%E6%B3%95
6
12
 
7
13
 
8
14
 
@@ -44,6 +50,12 @@
44
50
 
45
51
  private Ground spt_ground;//地面判定
46
52
 
53
+ private Vector3 n;
54
+
55
+
56
+
57
+ private Vector3 nomral;
58
+
47
59
 
48
60
 
49
61
  // Start is called before the first frame update
@@ -92,7 +104,11 @@
92
104
 
93
105
  move = move_x + move_z; //+ new Vector3(rb.velocity.x,0,rb.velocity.z);
94
106
 
95
- // move.y = gravity.y;
107
+ // move.y = gravity.y;
108
+
109
+
110
+
111
+ n = Vector3.ProjectOnPlane(move,nomral);
96
112
 
97
113
 
98
114
 
@@ -114,9 +130,7 @@
114
130
 
115
131
 
116
132
 
117
-
118
-
119
-
133
+
120
134
 
121
135
 
122
136
 
@@ -134,7 +148,11 @@
134
148
 
135
149
 
136
150
 
151
+
152
+
153
+
154
+
137
- rb.velocity = new Vector3(move.x, rb.velocity.y, move.z);
155
+ rb.velocity = new Vector3(n.x, rb.velocity.y, n.z);
138
156
 
139
157
  rb.AddForce(gravity);
140
158
 
@@ -144,7 +162,7 @@
144
162
 
145
163
  {
146
164
 
147
- rb.velocity = new Vector3(move.x, 0, move.z);
165
+ rb.velocity = new Vector3(n.x, 0, n.z);
148
166
 
149
167
 
150
168
 
@@ -158,13 +176,17 @@
158
176
 
159
177
 
160
178
 
179
+
180
+
161
181
  private void OnCollisionStay(Collision c)
162
182
 
163
183
  {
164
184
 
185
+ nomral = c.contacts[0].normal;
186
+
165
187
  isGround = true;
166
188
 
167
-
189
+
168
190
 
169
191
  gravity.y = 0;
170
192