I have a gun in my FPS. It shoot correct and now I want to add an explosion power to the bullets. But when I use this code, the bullets fly to the sky, when I shoot, not to that direction, to where I’m looking.
public GameObject explosion;
public GameObject armor;
float explosionRadius = 5.0f;
float explosionPower = 2000.0f;
void Start()
{
Collider[] colliders = Physics.OverlapSphere (
transform.position, explosionRadius);
foreach (var hit in colliders)
if (hit.rigidbody &&
hit.rigidbody.tag != "Player" &&
hit.rigidbody.tag != "Gun")
hit.rigidbody.AddExplosionForce (
explosionPower,
transform.position,
explosionRadius);
}
}