質問編集履歴
1
挙動がおかしくなる原因であった誤ったコード群と、質問に必要のない無駄なコードを削除。回答しようのない疑問点②を削除しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -13,50 +13,6 @@
|
|
13
13
|
水平移動のソースにコントローラースティックの傾き加減により加速させる仕様があるため、計算式がよくわからない事になっています。
|
14
14
|
|
15
15
|
移動に使われているソースを抜粋しました。
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
Controller.cs(コントローラーによる入力に関わるもの)
|
20
|
-
|
21
|
-
```
|
22
|
-
|
23
|
-
public class Controller : MonoBehaviour
|
24
|
-
|
25
|
-
{
|
26
|
-
|
27
|
-
void Awake(){playerCtrl = GetComponent<PlayerController>();}
|
28
|
-
|
29
|
-
void Update()
|
30
|
-
|
31
|
-
{
|
32
|
-
|
33
|
-
// 操作可能か?
|
34
|
-
|
35
|
-
if (!playerCtrl.activeSts) { return; }
|
36
|
-
|
37
|
-
// パッド処理
|
38
|
-
|
39
|
-
float joyMvX = Input.GetAxis("Horizontal");
|
40
|
-
|
41
|
-
float joyMvY = Input.GetAxis("Vertical");
|
42
|
-
|
43
|
-
playerCtrl.Horizontal_Move(joyMvX);
|
44
|
-
|
45
|
-
playerCtrl.Vertical_Move(joyMvY);
|
46
|
-
|
47
|
-
if (joyMvY > 0)//↑キーを押した状態
|
48
|
-
|
49
|
-
{playerCtrl.Movement_Object();}
|
50
|
-
|
51
|
-
if (joyMvY < 0 & !(Input.GetButtonDown("Jump") ))//落下
|
52
|
-
|
53
|
-
{playerCtrl.Movement_Object();}
|
54
|
-
|
55
|
-
}
|
56
|
-
|
57
|
-
}
|
58
|
-
|
59
|
-
```
|
60
16
|
|
61
17
|
|
62
18
|
|
@@ -118,143 +74,11 @@
|
|
118
74
|
|
119
75
|
}
|
120
76
|
|
121
|
-
public override void Vertical_Move(float n)//垂直移動
|
122
77
|
|
123
|
-
{
|
124
|
-
|
125
|
-
if (!activeSts) {return;}
|
126
|
-
|
127
|
-
moveSpeed = (moveSpeed < 0.5f) ? (moveSpeed * (1.0f / 0.5f)) : 1.0f;
|
128
|
-
|
129
|
-
speedVy = initSpeed * moveSpeed;
|
130
|
-
|
131
|
-
}
|
132
|
-
|
133
|
-
}
|
134
78
|
|
135
79
|
```
|
136
80
|
|
137
81
|
|
138
|
-
|
139
|
-
BaseCharacterController.cs
|
140
|
-
|
141
|
-
```
|
142
|
-
|
143
|
-
public class BaseCharacterController : MonoBehaviour {
|
144
|
-
|
145
|
-
public Vector2 velocityMin = new Vector2(-100.0f, -100.0f);
|
146
|
-
|
147
|
-
public Vector2 velocityMax = new Vector2(+100.0f, +50.0f);
|
148
|
-
|
149
|
-
public Vector2 CharacterPosition;//現在のキャラクターの座標
|
150
|
-
|
151
|
-
protected float speedVx = 0.0f;
|
152
|
-
|
153
|
-
protected float speedVxAddPower = 0.0f;
|
154
|
-
|
155
|
-
protected float speedVy = 0.0f;
|
156
|
-
|
157
|
-
protected float speedVyAddPower = 0.0f;
|
158
|
-
|
159
|
-
public Rigidbody2D RB;
|
160
|
-
|
161
|
-
[System.NonSerialized] public float dir = 1.0f;//方向の指定
|
162
|
-
|
163
|
-
[System.NonSerialized] public float speed = 1.0f;
|
164
|
-
|
165
|
-
[System.NonSerialized] public float basScaleX = 1.0f;
|
166
|
-
|
167
|
-
[System.NonSerialized] public bool groundedPrev = false;
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
protected virtual void FixedUpdate() {
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
//方向チェック
|
176
|
-
|
177
|
-
if (transform.localScale.x > 0.0f) { facing = true; }
|
178
|
-
|
179
|
-
else if (transform.localScale.x < 0.0f) { facing = false; }
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
// 移動計算
|
184
|
-
|
185
|
-
RB.velocity = new Vector2(speedVx, RB.velocity.y);
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
// Veclocityの値をチェック
|
190
|
-
|
191
|
-
float vx = Mathf.Clamp(RB.velocity.x, velocityMin.x, velocityMax.x);
|
192
|
-
|
193
|
-
float vy = Mathf.Clamp (RB.velocity.y, velocityMin.y, velocityMax.y);
|
194
|
-
|
195
|
-
RB.velocity = new Vector2(vx,vy);
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
//キャラクターの現在座標の記録
|
200
|
-
|
201
|
-
beforeCharacterPosition = CharacterPosition;
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
public virtual void Horizontal_Move(float n) {
|
206
|
-
|
207
|
-
if (grounded ==true && air == false)//滞空時に歩行アニメーションを表示させない
|
208
|
-
|
209
|
-
{
|
210
|
-
|
211
|
-
if (n != 0.0f)//左右に移動している
|
212
|
-
|
213
|
-
{
|
214
|
-
|
215
|
-
dir = Mathf.Sign(n);//移動している方向を-+でdirに出力
|
216
|
-
|
217
|
-
speedVx = speed * n;
|
218
|
-
|
219
|
-
animator.SetTrigger("Run");
|
220
|
-
|
221
|
-
}
|
222
|
-
|
223
|
-
else
|
224
|
-
|
225
|
-
{
|
226
|
-
|
227
|
-
speedVx = 0;
|
228
|
-
|
229
|
-
animator.SetTrigger("Idle");
|
230
|
-
|
231
|
-
}
|
232
|
-
|
233
|
-
}
|
234
|
-
|
235
|
-
}
|
236
|
-
|
237
|
-
public virtual void Vertical_Move(float n)
|
238
|
-
|
239
|
-
{
|
240
|
-
|
241
|
-
if (n != 0.0f)
|
242
|
-
|
243
|
-
{
|
244
|
-
|
245
|
-
dir = Mathf.Sign(n);
|
246
|
-
|
247
|
-
speedVy = speed * n;
|
248
|
-
|
249
|
-
}
|
250
|
-
|
251
|
-
}
|
252
|
-
|
253
|
-
}
|
254
|
-
|
255
|
-
}
|
256
|
-
|
257
|
-
```
|
258
82
|
|
259
83
|
### 疑問点
|
260
84
|
|
@@ -274,48 +98,4 @@
|
|
274
98
|
|
275
99
|
|
276
100
|
|
277
|
-
②
|
278
|
-
|
279
|
-
```
|
280
|
-
|
281
|
-
public override void Vertical_Move(float n)//垂直移動
|
282
|
-
|
283
|
-
{
|
284
|
-
|
285
|
-
if (!activeSts) {return;}
|
286
|
-
|
287
|
-
moveSpeed = (moveSpeed < 0.5f) ? (moveSpeed * (1.0f / 0.5f)) : 1.0f;
|
288
|
-
|
289
|
-
speedVy = initSpeed * moveSpeed;
|
290
|
-
|
291
|
-
}
|
292
|
-
|
293
|
-
```
|
294
|
-
|
295
|
-
```
|
296
|
-
|
297
|
-
public virtual void Vertical_Move(float n)
|
298
|
-
|
299
|
-
{
|
300
|
-
|
301
|
-
if (n != 0.0f)
|
302
|
-
|
303
|
-
{
|
304
|
-
|
305
|
-
dir = Mathf.Sign(n);
|
306
|
-
|
307
|
-
speedVy = speed * n;
|
308
|
-
|
309
|
-
}
|
310
|
-
|
311
|
-
}
|
312
|
-
|
313
|
-
```
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
101
|
+
②[無意味なコードであったことが分かりましたので、質問と言えず削除しました。]
|
318
|
-
|
319
|
-
上記部分のソースで最低限の垂直移動ができるのではないかと考えたのですが、Rigitboddy2D(重力)の有無に関係なく無反応でした。
|
320
|
-
|
321
|
-
エラーメッセージも出ていません。何か改善方法はありますでしょうか?
|