- Home /
GameObject not destroyed on Collision on Standalone - multi
My problem is that when I fire my projectile in multiplayer. When I have the Unity Editor Hosting the game it all works correctly, con collision with anything the projectile is destroyed. But when I build and run and Host from that version the projectiles are not destroyed on collision and bounce off the ground and go flying away. But on the Client which is the Unity Editor the projectiles are destroyed on collision. This causes a non existant projectile to hit the player miles out of its max range.
here is the snippet of the projectile code`
public float m_MaxLifeTime = 2f;
public float m_MaxDamage = 34f;
public float m_ExplosionRadius = 5;
public float m_ExplosionForce = 100f;
public ParticleSystem m_ExplosionParticles;
private void Start () {
Destroy (gameObject, m_MaxLifeTime);
}
private void OnCollisionEnter (Collision other) {
Rigidbody targetRigidbody = other.gameObject.GetComponent<Rigidbody> ();
if (targetRigidbody != null) {
targetRigidbody.AddExplosionForce (m_ExplosionForce, transform.position, m_ExplosionRadius);
TankHealth_Net targetHealth = targetRigidbody.GetComponent<TankHealth_Net> ();
if (targetHealth != null) {
float damage = CalculateDamage (targetRigidbody.position);
targetHealth.TakeDamage (damage);
}
}
m_ExplosionParticles.transform.parent = null;
m_ExplosionParticles.Play ();
Destroy (m_ExplosionParticles.gameObject, m_ExplosionParticles.main.duration);
Destroy (gameObject);
}
private float CalculateDamage (Vector3 targetPosition) {
Vector3 explosionToTarget = targetPosition - transform.position;
float explosionDistance = explosionToTarget.magnitude;
float relativeDistance = (m_ExplosionRadius - explosionDistance) / m_ExplosionRadius;
float damage = relativeDistance * m_MaxDamage;
damage = Mathf.Max (0f, damage);
return damage;
}
`
Your answer
Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
Don't destroy player after disconnecting or calling ClientScene.RemovePlayer() 1 Answer
Network.Destroy doesn't remove objects on other systems? 2 Answers
How to destroy child object of other player with UNET? 1 Answer
Do i need to have 2 seperate apps communicating for server/client relationship? 2 Answers