I’m making a game where several enemies are chasing you down and you can defend yourself with bombs. When these bombs hit something, they explode. When colliding with an explosion, the enemies fly away with a proportionate “explosion push force”:
// Push me back from the center of the explosion
Vector3 fromExplosionToMe = gameObject.transform.position - objHit.transform.position;
gameObject.GetComponent<Rigidbody> ().AddForce (
fromExplosionToMe * Bomb.ExplosionPushForce * Time.deltaTime,
ForceMode.Impulse);
The trouble is that, sometimes, when that enemy hits ANOTHER enemy while he flies away from the explosion, that other enemy flies away at massive speeds and away from the screen:
I first thought that the problem could be that I was moving the enemies towards the player with translations instead of with forces, so when a force-powered enemy collided with a translation-powered enemy it would result in awkward physics. However, after converting all the translation movements to physics, I’m still having the problem:
// Non-physics-based movement (OLD)
//gameObject.transform.position =
// Vector3.MoveTowards(gameObject.transform.position,
// player.transform.position,
// MOVE_SPEED * Time.deltaTime);
// Physics-based movement (NEW)
gameObject.GetComponent<Rigidbody> ().MovePosition (
Vector3.MoveTowards(gameObject.transform.position,
player.transform.position,
MOVE_SPEED * Time.deltaTime));
Has anyone had a similar experience with collisions that result from other collisons?
Thanks in advance!