I’ve noticed on unity3d forums that some people have had issues with AddExplosionForce() only affecting the rigidbody in the Y direction, I am experiencing this myself.
I’m using it via a network. So, I have a missile and when it explodes it’s supposed to add the explosionforce on it’s position when it collides with something.
Now for the odd behaviour. If the client fires a missile at the server player, the server player receives the correct explosion force. But if the server fires the missile at the client player, it explodes on contact, but the explosion only drives the player upwards on their Y direction. This happens on each consecutive client player and looks like only the server receives the true explosion physics.
Does anyone know why this may be happening?
Heres my code (attached to the missile):
void OnCollisionEnter (Collision collision)
{
transform.rigidbody.isKinematic = true;
if (Network.isServer !isDestroyed){
ContactPoint contact = collision.contacts [0];
Quaternion rotation = Quaternion.FromToRotation (Vector3.up, contact.normal);
Vector3 explosionPosition = transform.position;//contact.point;
networkView.RPC("DestroyRocket", RPCMode.All, explosionPosition , rotation, transform.forward);
isDestroyed = true;
}
}
[RPC]
void DestroyRocket(Vector3 explosionPosition, Quaternion rotation, Vector3 dir){
Collider[] colliders = Physics.OverlapSphere (explosionPosition, explosionRadius);
foreach (Collider hit in colliders) {
if (hit.rigidbody) {
hit.transform.rigidbody.AddExplosionForce (explosionPower, explosionPosition, explosionRadius, 3.0f);
}
}
Destroy(gameObject);
}
If anyone has an alternative to using AddExplosionForce() that would also be great.