0
\$\begingroup\$

I'm using SmartFoxServer for a 3D multi-player shooter game in Unity

I need to add some destructible objects in the game, so I tried these assets:

It works for a single player but I'm not sure how to notify the server to run the same destructions for other players

\$\endgroup\$

3 Answers 3

0
\$\begingroup\$

There are for sure more that one way to achieve this. I am not familiar with smartfox server's setup to help you on that regard & there is no point on writing about all the possible routes you could take since this topic may result in a huge discussion.

No matter what way of networking setup you do you should have to 'simulate' that destruction on the client.

Assuming that you have a function that destroys a house for whatever reason on your clientside code:

void Demolish(Object objectToDemolish, Type demolishType) {
// Do clientside gameengine stuff
}

To continue here I will assume the following scenario is happening in your game:

1) There are two players in the game and each player character is a tank
2) player 1 fires at a house 2.5) player 1 needs to notify the server for either the destruction or the firing based on the architecture of the game
3) the house is destroyed on player 1's client
4) player 2 is notified on the event
5) the house is destroyed on player 2's client

on step 3 since the house demolition occurs on the same client from where the event (step 2) is triggered it is fairly easy to find your house game object call your function with it as a parameter and the same goes with the demolition type.

However, player 2 will have be notified from the server with certain data in order for the client to know what to do. By using those data you will have to find the game object that needs to be demolished on the second client.

For example:

Object findGameObject(objectId) {
  // should return a game object based on its object id
  return GameObjectHolder.getById(objectId);
}

void HandleServerMessage(message) {
  switch(message.code) {
    case "object_destroy"
      Demolish(findGameObject(message.data.objectId), message.data.type);
      break;
    // other networking related procedures here
    defaults:
      break;
  }
}

Now whether player 1 will also notified by the server or by the client itself is another story, that is based on your architecture.

case authoritative server: you do not notify the server from firing client 1 for the destruction, but you notify it for the firing.

action: that means that the server will calculate where that firing will destroy an object. If it does, all clients will be notified of the destruction from the server, including client 1.

case non authoritative server: you do notify the server on destruction, so that the server skips that calculation. Plus you want an immediate response on the game UI, so that it does not appear laggy.

action: call the firing client 1's destruction method on collision between the bullet & the object. All other clients should be notified through server anyway. Just make sure not to try to destroy twice the same object.

\$\endgroup\$
1
\$\begingroup\$

On the most basic level, if your destruction algorithm is deterministic then the server can notify each client and the result should be the same.

The more complicated manner is that this system is notify independent of your other systems. It will probably be best for you to handle destruction in the same way.

E.g., if you are calculating trajectories and impacts at the client initiating the event, then you should do the same for your destruction. If your client notifies the server and the server makes the calculations, do the same for destruction.

If may also be worth investing your current methodology and consider changing if it is not up to the task.

\$\endgroup\$
0
\$\begingroup\$

I am guessing that in your case, clients are sending all their shots to the server, and the server is broadcasting them back to clients.

Basically, your clients should simulate the physics (animations and sounds as well) based on objective information coming from the server. This data can be differently structured:

  • One approach is sending data about who is shooting, from which position and which direction. Then every client could simulate the bullet trajectory and check for collisions for further physic interactions. One problem here would be to make sure that all physics simulations done by the clients would end up being the same. But, this is probably one of the easiest solution.
  • You might also do a part of physics in the server side, checking not only for player collisions, but also for collisions against walls/objects. This requires extra programming in the server side depending on the technologies you are using.
  • You can handle the destruction physics on the server side and send the simulation to the clients, but this is probably overkill in terms of CPU and bandwith. The benefit would be making sure that every client renders the same.

Points to be considered:

  • Latency compensation techniques: the information that you send/receive might be out of date, so performing as many calculations as possible in the server side should be the most accurate. You can find a good article about this here.
  • Security: if you let all the physics be done in the client-side, hackers can easily make wall-hacks, for instance.
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .