better understanding on who owns what?

Options
I need a better understanding on how to know who owns what. the view ids as far as I can tell are being set to the first person that joins. But how can I allocate view ids to certain people. How can I find a player by a view id. For instance I have a bullet prefab that gets instantiated when you shoot. I'm not giving it a network view, but I'm having it find A player that has my playerhitscan script then sending out rpcs through that script which is on a player that gets photon instantiated on start. But I don't at the moment know how to specifically have the bullet find that script by the master player or whoever i want it to. So far I'm using GameObject.Find("PlayerHitscan").getComponent<playerHitscan>() which will cause a lot of lag for shooting. I need to know how to ID players and find scripts by certain players and have the player im looking for cached already etc... Thanks in advance.

Comments

  • Tobias
    Options
    Don't instantiate bullets.
    I have to make this a blog post or so :)

    You could use RPCs for bullets telling everyone where the bullet was fired and in which direction. Everything else can be deducted. The bullet will hit something and be destroyed. That's all. You don't have to sync it's position, you don't need to remove it from the list of networked game objects either.
    The last parameter of a RPC method can be of type PhotonMessageInfo. This will contain who shot. Basically the bullet's owner. You can use this to cache your bullets, etc. The player who shot might also decide if he hit something and send a "hit" RPC, too.

    > So far I'm using GameObject.Find("PlayerHitscan").getComponent<playerHitscan>() which will cause a lot of lag for shooting.
    How that?


    ViewIDs are not assigned by the first player in a room. They are composed numbers of the player-ID (per room) * 1000 plus a sequence number used to identify this user's PhotonView. That makes 1001 the first object of player 1 and 4047 the 47th object of player 4 (in any room).
  • cj31387
    Options
    well I mean how can i make a reference to each player that I can always access to find specific players. Instead of using GameObject.Find() I need to know some way to find a player and access its components. Like say I shoot a enemy how could I send back data to the shooter that the enemy died through a reference of the player that shot? I just want to know all the ways to keep track of all players.
  • Tobias
    Options
    PhotonNetwork.playerList gives you access to the player instances. At the moment, those don't have references to all their GameObjects but you could cache that once you found them.