Question regarding missile and explosion over network

I couldn’t get the “AddExplosionForce()” working correctly over the network. So here is what I did, I’d like to get someone’s opinion if this is the only way to do it…

MY PREVIOUS PROBLEM:

The server always updated the missiles position and also had authority over whether it hit something. So, if a client was to shoot a missile at the server, since the server is doing all the checking and has the most up-to-date position and state of the missile, the player that’s on the server always received the correct “explosion” physics when the “AddExplosionForce()” function was instantiated.

If a server shot the missile at the client however, it would instantiate it like normal on both the client’s and server’s game. If on the server end, the missile collided with the client, the server would send an RPC call to the client basically saying “explode the missile and create an AddExplosionForce() at the missile’s position”. The problem with this was, that by the time the client would of got that message, the missile may of entered within the player’s collider, therefore, instantiating the explosion from inside the player’s collider, making them just go straight up.

MY SOLUTION:

When the missile gets instantiated on both the client and server, each one player sends the missile in the direciton it’s supposed to go, and each player check to see if it hit something. This works great, but I am concerned about lag and the missiles not being in sync… I assume there will be instances where the missile will explode on one players screen, but keep going on the other players screen.

If anyone has any input on whether this is the only way to do it, let me know.

The only way around this is lag compensation and interpolation. Just like you would do with the players in a multiplayer game.

The best solution would probably be to not have the clients do AddExplosionForce() at all, only have the server do it and have the server be authoritative over the client’s rigidbody physics.

Ah, ok thanks.

Hm trying this approach, the AddExplosionForce() works fine if the client shoots at the server, but when the server tries to AddExplosionForce() to the client, the client just nudges over (i think it’s from the missile hitting the player), but the AddExplosionForce() is not applied to the player. This is what I have:

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 = contact.point;//contact.point;
			

			networkView.RPC("DestroyRocket", RPCMode.All, explosionPosition, rotation);
			
			//DestroyRocketLocal(explosionPosition, rotation);
			
			isDestroyed = true;
		}
	}
[RPC]
	void DestroyRocket(Vector3 explosionPosition, Quaternion rotation){
		
		GameObject instantiatedExplosion = (GameObject)Instantiate (explosion, explosionPosition, rotation);
		//transform.rotation = rotation;

			
		Collider[] colliders = Physics.OverlapSphere (explosionPosition, explosionRadius);
		
		foreach (Collider hit in colliders) {
			if (hit.rigidbody) {
				if (Network.isServer){
					
					hit.rigidbody.AddExplosionForce (explosionPower, explosionPosition, explosionRadius, 3.0f);
				}
			}	
			
			
			
		}


		Destroy(gameObject);
		
	}