Shooting a fireball

I'm just starting to look into Photon. I got the Viking demo working with Photon Cloud very easily, and I'm impressed. However, I'm curious about how I would go about shooting a fireball. The examples generally use raycasts for collision, as bullets shoot fast enough that "instant" is good enough. What if I wanted a dodge-able projectile?

Would I Instantiate a new network object for everyone to see? Or would I issue an RPC, causing the "local" representation of that player to shoot a fireball from a certain position in a certain direction? How would I handle the collision for that fireball as it travels? Will this cause the fireball to hit a player on one client, but miss the same player on another client, depending on latency? Does the "master" client decide whether it hits? How do I figure out which client is the Master client, and how do I get the other clients to ignore that logic? This might just be basic networking logic, but I have no idea how to solve these problems.

Sorry for all the noobish questions, I hope someone can help.

Thanks in advance.

Comments

  • Glad you like Photon Cloud so far.

    And you actually have quite good ideas and suggestions.
    Yes, due to lag you might run into issues with dodge-able projectiles. It's a bit tricky and the effort you want to put into it depends on your requirements. A cooperative game could get away with some more sync errors than a game that's highly competitive and where gameplay is about money.

    Only one client should decide if a projectile hits something. The Master Client (PhotonNetwork.isMasterClient) is a good candidate but alternatively the shooting client could decide.
    Either way, not all positions will be in perfect sync.
    Hiding lag can be done in several ways:
    • Fast-forward an incoming position (skip some distance missed due to lag). This requires to use the network time to sync.
    • Moving objects a bit faster to catch up with last received position. This requires to use the network time to sync.
    • Send user-input immediately while executing it locally with a delay.

    I don't have implementations for these cases, sadly. Which one is best for your, depends a lot on your game.
  • I have a similar question. When I launch a fireball using NetworkInstantitate, and a third person joins, he sees the fireball at the orignal position in the beginning. So it seems the only solution is to use RPC to inform new players to spawn in the right position correctly, which sorts of defeats the purpose of NetworkInstatiate.

    I see there's Cache events but not supported by Cloud?
  • The event is cached but in it's original state. The cache doesn't update.
    Firing each fireball via instantiate is some overhead. It caches a short-lived game object which needs to be cleared, too.
    You could just send a RPC for "firing" and later on sync the result. If someone joins, he will not see the fireball but everything that's happening after the join, which might be enough.
  • That's not as ideal. If there is some object which is spawn early, and lives for every long, the new players don't see it. So it seems I still have to keep a manual list of entities that a new player should see, and send RPC to create it.
  • I'm not sure if it's better to have the buffered instantiate call automatically send the latest position/rotation over.

    In the meanwhile you can easily use:

    void OnPhotonPlayerConnected(PhotonPlayer newPlayer){ ... } //Use this on the object to have the owner send a RPC to the newly connected player with the correct pos/rot

    void OnPhotonInstantiate(PhotonMessageInfo info){ ... } //you could use this on the player that has connected later and receives this object..it could request up2date information or so (not required if you use OnPhotonPlayerConnected instead)


    I would still prefer this over keeping a manual list as it abstracts the creating/destroying for you.
  • Hmm. I'm not getting the thread notifications.
    In the meanwhile you can easily use:

    void OnPhotonPlayerConnected(PhotonPlayer newPlayer){ ... } //Use this on the object to have the owner send a RPC to the newly connected player with the correct pos/rot

    Would this mean I have to keep track of items myself. Which I plan on doing.