Instantiating Query... Please Help!

I am building an Augmented reality First Person Shooter. My idea on building this game is that a gameobject spawns on the location of the Host and the Client and follows them respectively. This gameobject can be used as a collider to detect when raycasting. But the problem i am facing is that both the gameobjects are spawning at the same position and following my camera in my view and opponents camera in his view. So we cannot differentiate the client and host in their respective cameras.

if(BoltNetwork.IsClient)
{
GameObject Player1 = BoltNetwork.Instantiate(BoltPrefabs.Player1, Vector3.zero, this.gameobject.transform.rotation);
}
if(BoltNetwork.IsServer)
{
GameObject Player2 = BoltNetwork.Instantiate(BoltPrefabs.Player2, Vector3.zero, this.gameobject.transform.rotation);
}

This is the code i am using.

Thanks in Advance!!!!
:smile:

Comments

  • Hello @Manhiem ,

    Generally, on cases like this, each entity has its own camera, but it's disabled by default.
    When a specific player creates the entity and it's attached (https://doc-api.photonengine.com/en/bolt/current/class_bolt_1_1_entity_behaviour.html#a21d8a26e1e8197164ea49ee5a7a5a640 plus entity.IsOwner) or the player gains control (https://doc-api.photonengine.com/en/bolt/current/class_bolt_1_1_entity_behaviour.html#a09ddf209aa2ac133ecbb209cb8d9ddb7) over the entity, the local camera of that entity is enabled, so you don't have multiple enabled cameras.

    --
    Ramon Melo
    Photon Bolt Team
  • Manhiem
    Manhiem
    edited September 2020
    Thank You for your comment Sir.

    public override void Attached()
    {
    if(entity.IsOwner)
    {
    fpsCam.SetActive(true);
    }
    else
    {

    }

    }

    Could you please tell me what to add in the else statement so that the cube moves along the camera. Even if the camera is not active in the view of the opponent.
  • Manhiem
    Manhiem
    edited September 2020
    @ramonmelo

    Sir how can I send the location of player1 to the server which will be recieved by player2?
    According to me this is the only way to share locations of both the players!
  • Hello @Manhiem ,

    Please, follow the Getting Started Sample with Photon Bolt: https://doc.photonengine.com/en-us/bolt/current/demos-and-tutorials/bolt-basics/bolt-101-wizard-setup

    There, you will see that entities are made of their own state, that you define to be synchronized across the server and clients. With this in mind, you can select a particular entity and read it's current state values, for example.

    About the code, this is very specific of your game, there is no general answer for this.
    There are two main approaches to this:

    1. Each player has it's own camera disabled, which is a child of its own transform, so the camera will move together of the player visuals when it is activated for the local player.
    2. You have a global camera, but when the local player is instantiated, it's passed as a target transform the camera needs to follow. You can take a look at this script from the Advanced Tutorial: https://github.com/BoltEngine/Bolt-Sample/blob/master/AdvancedTutorial/scripts/Player/PlayerCamera.cs
  • @ramonmelo
    I have updated my Script in this way:

    public void Update()
    {
    if(entity.IsOwner)
    {
    Root.SetActive(true);
    }

    if(BoltNetwork.IsServer)
    {
    entity.GetState<ICubeState>().X1 = fpsCam.transform.position.x;
    entity.GetState<ICubeState>().Y1 = fpsCam.transform.position.y;
    entity.GetState<ICubeState>().Z1 = fpsCam.transform.position.z;

    Serverpos.x = entity.GetState<ICubeState>().X1;
    Serverpos.y = entity.GetState<ICubeState>().Y1;
    Serverpos.z = entity.GetState<ICubeState>().Z1;
    }

    if(BoltNetwork.IsClient)
    {
    entity.GetState<ICubeState>().X2 = fpsCam.transform.position.x;
    entity.GetState<ICubeState>().Y2 = fpsCam.transform.position.y;
    entity.GetState<ICubeState>().Z2 = fpsCam.transform.position.z;

    Clientpos.x = entity.GetState<ICubeState>().X2;
    Clientpos.y = entity.GetState<ICubeState>().Y2;
    Clientpos.z = entity.GetState<ICubeState>().Z2;
    }
    }

    Root holds the ARCamera and Device.
    fpsCam holds the ARCamera whose location is being updated.

    Here, X1, Y1, Z1 are float state properties which hold the location values of the Server and X2, Y2, Z2 of the client. Till the client joins the server, everything is fine.

    But the moment the client joins, this error pops out saying "Only Owner can modify X1", in server side and "Only owner can modify X2", in the client side.

    Is there any solution or a better way to do?
  • Hello @Manhiem ,

    Please, follow the Photon Bolt tutorials, so you can get a better idea of how you can modify the state from an Entity. Our documentation is extensive with a lot of details about those topics, we suggest the following pages to start:

    - https://doc.photonengine.com/en-us/bolt/current/demos-and-tutorials/bolt-basics/bolt-101-wizard-setup
    - https://doc.photonengine.com/en-us/bolt/current/gameplay/boltentity
    - https://doc.photonengine.com/en-us/bolt/current/reference/glossary

    You need to consider your entities as being controlled by only one player at the time, not being filtered by the type of client you are connecting from (if it's a server or client). Again, follow the tutorials so you can get a better idea of how to structure your game based on how Bolt help your to layout your controllers.