Different models for client and remote players

Hi all, I am in the middle of making my new FPS multiplayer game and have chosen BOLT for the network solution.
One of the challenges I have still yet to solve is how I spawn different prefabs depending on whether I'm the player or looking at a player( For example: My hands, gun and camera for the player and just the model with the gun for someone that's looking at the player)

I have read the Entity Pooling document, but it really did not give an example on how to implement the very thing it was discussing.
I have tried to mess with stuff like if(entity.isOwner), but have yet to come to a solution.

Any help would be appreciated.

Comments

  • Hi,

    The simplest solution, in this case, is just to have one type of Prefab for the Player, with both the "Full Body" and the "Only-Arms" models, but enable/disable only the part that you will be using for the local player.

    This should be easily done using Entity Ownership ( https://doc.photonengine.com/en-us/bolt/current/gameplay/boltentity#entity_ownership ), but it depends on how you are managing your clients.

    - If you are using a Server Authoritative with Clients being the controllers of the entities, just check if the Client has control ("entity.hasControl" or override the "ControlGained" callback) and enable the arms rig, if not, enable the full body.
    - If your clients are the owner of the characters, so just check the ownership ("entity.isOwner") and do the same.

    --
    Ramon Melo
    Photon Bolt Team
  • ramonmelo wrote: »
    Hi,

    The simplest solution, in this case, is just to have one type of Prefab for the Player, with both the "Full Body" and the "Only-Arms" models, but enable/disable only the part that you will be using for the local player.

    This should be easily done using Entity Ownership ( https://doc.photonengine.com/en-us/bolt/current/gameplay/boltentity#entity_ownership ), but it depends on how you are managing your clients.

    - If you are using a Server Authoritative with Clients being the controllers of the entities, just check if the Client has control ("entity.hasControl" or override the "ControlGained" callback) and enable the arms rig, if not, enable the full body.
    - If your clients are the owner of the characters, so just check the ownership ("entity.isOwner") and do the same.

    --
    Ramon Melo
    Photon Bolt Team

    Hi Ramon, thanks for the suggestion, unfortunately when you try to add animations everything stops working. here's the code i'm using


    PlayerBehaviour.cs:

    public class PlayerBehaviour : EntityBehaviour<ICustomPlayerState>
    {
    public GameObject firstPersonModel;
    public GameObject thirdPersonModel;

    public static bool isLocalPlayer;

    public override void Attached()
    {
    if(entity.IsOwner)
    {
    isLocalPlayer = true;
    firstPersonModel.SetActive(true);

    }
    else
    {
    isLocalPlayer = false;
    thirdPersonModel.SetActive(true);
    }
    }
    }



    Gun.cs(just a snippet, but should be enough to understand how i tried to implement everything):

    if(!PlayerBehaviour.isLocalPlayer)
    {
    thirdPersonAnimator.Play("Fire", 0, 0);
    }
    else
    {
    firstPersonAnimator.Play("Fire", 0, 0);
    }



    This unfortunately does not work. if i disable them both in the prefab and enable them like this in the script and try to trigger an event for an animation it says that the animator is inactive, but the game still continues its course without failing.

    if i destroy based on whichever player is viewing (for example if(entity.IsOwner){Destroy(thirdPersonObject);}
    I get an error saying that i cannot animate with a destroyed animator.

    Could you please give a working code example so maybe i can fix my own if i'm doing something wrong?

    Thanks in advance.


  • Hi @EyalolGadol ,

    Sorry, but we don't have a sample showing how to implement this.

    Our suggestion is based on how you can enable/disable parts of your player character based on the characteristics of your peer, (if he is the controller or owner, server, or client) which are directly related to how Bolt can help you identify those cases.

    Even without using Bolt, you should be able to just toggle between a Full-Body and Arms-Only player, with all the animations and the necessary behaviors, as this is not related to Bolt itself.

    Another suggestion that we've seen is:

    Have inside your Character model Two meshes, one with the full body and another with only the arms. This way, both use the same bones and are animated at the same time.
    Building a model like this, enables you to, instead of disabling the complete chain of the game objects of one type (body or arms), you will only disable the GO with the "Skinned Mesh Renderer" attached that you want to hide.

    --
    Ramon Melo
    Photon Bolt Team