質問編集履歴
3
問題が起こる状況を書き加えました。また、予想も立ててみました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -30,8 +30,11 @@
|
|
30
30
|
Big Enemyにplayerが接触したとき、吹き飛ばされるはずがくっついて離れなくなってしまうことがあります。
|
31
31
|
|
32
32
|
Nomal Enemyも同じように吹き飛ばされるスクリプトを書いてありますが、Nomal Enemyにはこのようなことがありません。
|
33
|
-
また特に、Big Enemyが登場するとき、上空から落下してくるのですが、落下しGroundに着地した瞬間にPlayerがBig Enemyに触れているとこの問題が起きやすいように感じます。
|
33
|
+
また特に、Big Enemyが登場するとき、上空から落下してくるのですが、落下しGroundに着地した瞬間にPlayerがBig Enemyに触れているとこの問題が起きやすいように感じます。さらに、BigEnemyが出現した瞬間に、それの下に潜り込むように接触しに行くと、それ以降PlayerがBigEnemyから離れなくなりました。
|
34
34
|
|
35
|
+
######予想
|
36
|
+
敵の下に潜り込んだ時に起こっているため、BigEnemyから下向きの力が加わって、弾き飛ばされるはずが、地面に押し付けられているようになっているのかもしれません。
|
37
|
+
|
35
38
|
### 該当のソースコード
|
36
39
|
|
37
40
|
```C#
|
2
補足:Playerのscriptを追加しました。時数の制限によって、不要だと思われる部分は省略しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -146,7 +146,181 @@
|
|
146
146
|
|
147
147
|
```
|
148
148
|
|
149
|
+
######補足 Playerのscript
|
150
|
+
```C#
|
151
|
+
using System.Collections;
|
152
|
+
using System.Collections.Generic;
|
153
|
+
using UnityEngine;
|
154
|
+
using UnityEngine.SceneManagement;
|
155
|
+
using UnityEngine.UI;
|
149
156
|
|
157
|
+
public class PlayerController : MonoBehaviour
|
158
|
+
{
|
159
|
+
private GameObject focalPoint;
|
160
|
+
public GameObject powerupIndicator;
|
161
|
+
public GameObject specialWeaponIndicator;
|
162
|
+
public GameObject nomalEnemyPrefab;
|
163
|
+
|
164
|
+
private Rigidbody playerRb;
|
165
|
+
private Rigidbody nomalEnemyPrefabRb;
|
166
|
+
|
167
|
+
public float powerUpStrengh = 15.0f;
|
168
|
+
public float defaltSpeed = 5.0f;
|
169
|
+
|
170
|
+
public bool hasPowerup = false;
|
171
|
+
public bool readyToRanchSpecialWeapon = false;
|
172
|
+
public bool hasSpecialWeapon = false;
|
173
|
+
public bool gameOver = false;
|
174
|
+
public static bool cameraForwardType = false;
|
175
|
+
public bool onGround;
|
176
|
+
public bool blownAwayByPlayerWithSpecialWeapon = false;
|
177
|
+
|
178
|
+
|
179
|
+
public ParticleSystem bigShockParticle;
|
180
|
+
public ParticleSystem smallShockParticle;
|
181
|
+
|
182
|
+
private AudioSource playerAudio;
|
183
|
+
public AudioClip highBounceSound;
|
184
|
+
public AudioClip coinSound;
|
185
|
+
public AudioClip lowBounceSound;
|
186
|
+
public AudioClip BigBounceSound;
|
187
|
+
public AudioClip getSpecialWeaponSound;
|
188
|
+
|
189
|
+
// Start is called before the first frame update
|
190
|
+
void Start()
|
191
|
+
{
|
192
|
+
Time.timeScale = 1.0f;
|
193
|
+
|
194
|
+
focalPoint = GameObject.Find("Focal Point");
|
195
|
+
|
196
|
+
playerRb = GetComponent<Rigidbody>();
|
197
|
+
nomalEnemyPrefabRb = nomalEnemyPrefab.GetComponent<Rigidbody>();
|
198
|
+
|
199
|
+
playerAudio = GetComponent<AudioSource>();
|
200
|
+
}
|
201
|
+
|
202
|
+
// Update is called once per frame
|
203
|
+
void Update()
|
204
|
+
{
|
205
|
+
Move();
|
206
|
+
|
207
|
+
Jump();
|
208
|
+
|
209
|
+
Destroy();
|
210
|
+
}
|
211
|
+
|
212
|
+
private void Move()
|
213
|
+
{
|
214
|
+
if (!readyToRanchSpecialWeapon)
|
215
|
+
{
|
216
|
+
float speed;
|
217
|
+
if (cameraForwardType)
|
218
|
+
{
|
219
|
+
float forwardInput = Input.GetAxis("Vertical");
|
220
|
+
|
221
|
+
if (onGround)
|
222
|
+
{
|
223
|
+
speed = defaltSpeed;
|
224
|
+
}
|
225
|
+
else
|
226
|
+
{
|
227
|
+
speed = defaltSpeed * 0.3f;
|
228
|
+
}
|
229
|
+
|
230
|
+
playerRb.AddForce(focalPoint.transform.forward * speed * forwardInput);
|
231
|
+
}
|
232
|
+
else
|
233
|
+
{
|
234
|
+
float verticalInput = Input.GetAxis("Vertical");
|
235
|
+
float horizontalInput = Input.GetAxis("Horizontal");
|
236
|
+
|
237
|
+
if (onGround)
|
238
|
+
{
|
239
|
+
speed = defaltSpeed;
|
240
|
+
}
|
241
|
+
else
|
242
|
+
{
|
243
|
+
speed = defaltSpeed * 0.3f;
|
244
|
+
}
|
245
|
+
playerRb.AddForce(focalPoint.transform.forward * speed * verticalInput);
|
246
|
+
playerRb.AddForce(focalPoint.transform.right * speed * horizontalInput);
|
247
|
+
}
|
248
|
+
}
|
249
|
+
}
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
|
254
|
+
private void OnTriggerEnter(Collider other)
|
255
|
+
{
|
256
|
+
if (other.CompareTag("Powerup") && !hasPowerup)
|
257
|
+
{
|
258
|
+
hasPowerup = true;
|
259
|
+
Destroy(other.gameObject);
|
260
|
+
StartCoroutine(PowerupCountdownRoutine());
|
261
|
+
StartCoroutine(SetPowerupIndicatorPosition());
|
262
|
+
|
263
|
+
playerAudio.PlayOneShot(coinSound, 0.4f);
|
264
|
+
}
|
265
|
+
|
266
|
+
if (other.CompareTag("Special Weapon") && !hasSpecialWeapon && onGround)
|
267
|
+
{
|
268
|
+
|
269
|
+
hasSpecialWeapon = true;
|
270
|
+
Destroy(other.gameObject);
|
271
|
+
|
272
|
+
StartCoroutine(SetSpecialWeaponIndicatorPosition());
|
273
|
+
|
274
|
+
StartCoroutine(SetSpecialWeapon());
|
275
|
+
|
276
|
+
playerAudio.PlayOneShot(getSpecialWeaponSound, 1f);
|
277
|
+
}
|
278
|
+
}
|
279
|
+
|
280
|
+
IEnumerator PowerupCountdownRoutine()
|
281
|
+
{
|
282
|
+
powerupIndicator.gameObject.SetActive(true);
|
283
|
+
yield return new WaitForSeconds(7);
|
284
|
+
hasPowerup = false;
|
285
|
+
powerupIndicator.gameObject.SetActive(false);
|
286
|
+
}
|
287
|
+
|
288
|
+
IEnumerator SetPowerupIndicatorPosition()
|
289
|
+
{
|
290
|
+
while (hasPowerup)
|
291
|
+
{
|
292
|
+
powerupIndicator.transform.position = transform.position + new Vector3(0, -0.5f, 0);
|
293
|
+
|
294
|
+
yield return null;
|
295
|
+
}
|
296
|
+
}
|
297
|
+
|
298
|
+
|
299
|
+
|
300
|
+
private void OnCollisionEnter(Collision collision)
|
301
|
+
{
|
302
|
+
if ((collision.gameObject.CompareTag("Nomal Enemy") || collision.gameObject.CompareTag("Mitosis Enemy")) && hasPowerup)
|
303
|
+
{
|
304
|
+
Rigidbody nomalEnemyRigidbody = collision.gameObject.GetComponent<Rigidbody>();
|
305
|
+
Vector3 awayFromPlayer = collision.gameObject.transform.position - transform.position;
|
306
|
+
|
307
|
+
nomalEnemyRigidbody.AddForce(awayFromPlayer * powerUpStrengh, ForceMode.Impulse);
|
308
|
+
smallShockParticle.Play();
|
309
|
+
//Debug.Log("Player collided with: " + collision.gameObject.name + " with powerup set to " + hasPowerup);
|
310
|
+
|
311
|
+
playerAudio.PlayOneShot(highBounceSound, 4f);
|
312
|
+
}
|
313
|
+
else if ((collision.gameObject.CompareTag("Nomal Enemy") || collision.gameObject.CompareTag("Mitosis Enemy")) && !hasPowerup)
|
314
|
+
{
|
315
|
+
playerAudio.PlayOneShot(lowBounceSound, 0.6f);
|
316
|
+
}
|
317
|
+
|
318
|
+
|
319
|
+
}
|
320
|
+
|
321
|
+
}
|
322
|
+
```
|
323
|
+
|
150
324
|
### 補足情報(FW/ツールのバージョンなど)
|
151
325
|
unity 2020.1.2f1
|
152
326
|
windows10
|
1
どのようなときにエラーが起こるのか詳しく書きました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -6,23 +6,32 @@
|
|
6
6
|
Big Enemy
|
7
7
|
Nomal Enemy
|
8
8
|
Player
|
9
|
+
|
9
10
|
がここでは登場しますが、
|
11
|
+
|
10
12
|
Massは
|
11
13
|
Big Enemy 1500
|
12
14
|
Nomal Enemy 5
|
13
15
|
Player 5
|
16
|
+
|
14
17
|
です。
|
18
|
+
|
15
19
|
それぞれColliderのMaterialは
|
20
|
+
|
16
21
|
Dynamic Friction 0.6
|
17
22
|
Static Friction 0.6
|
18
23
|
Bounciness 1
|
19
24
|
Friction Combine Average
|
20
25
|
Bounce Combine Multiply
|
26
|
+
|
21
27
|
となっています。
|
22
28
|
|
23
29
|
### 発生している問題・エラーメッセージ
|
24
30
|
Big Enemyにplayerが接触したとき、吹き飛ばされるはずがくっついて離れなくなってしまうことがあります。
|
25
31
|
|
32
|
+
Nomal Enemyも同じように吹き飛ばされるスクリプトを書いてありますが、Nomal Enemyにはこのようなことがありません。
|
33
|
+
また特に、Big Enemyが登場するとき、上空から落下してくるのですが、落下しGroundに着地した瞬間にPlayerがBig Enemyに触れているとこの問題が起きやすいように感じます。
|
34
|
+
|
26
35
|
### 該当のソースコード
|
27
36
|
|
28
37
|
```C#
|