playMaker

Author Topic: Photon Pickup Manager  (Read 7075 times)

Fletch

  • Junior Playmaker
  • **
  • Posts: 66
    • SneakOnTheLot.com
Photon Pickup Manager
« on: July 16, 2013, 11:54:52 AM »
Okay, I've had a breakthrough over the last 24 hours with the whole Photon/Multi-Player thing.  I've got a lot of it figured out but before I begin this next step, I'd like a little confirmation or direction.

I now have characters running around picking up gold, chatting, AI chasing them and causing damage to their hit points.  I've got footstep sounds, Dynamic cameras that change positions dependent on what the character is doing and a few other fun things.

I now need to implement a gold pickup manager.  What I have currently are gold prefabs that spawn in at specific points when a new player enters the game.  What I need is a gold spawning manager that finds random locations and spawns in gold after a specified period of time.

The problem with this is that if I create a new game object in the player hierarchy then have it handle the spawning, when a new player comes in more gold spawning will begin... rinse and repeat for every player. 

My plan is to make the Spawn Manager off by default and when the Master Player creates the room, turn their Spawn Manager on.  So, if you're the Master Player it will turn your Spawn Manager on.  Is this a good method?  Just wondering what the standard practice is here.

Fletch

  • Junior Playmaker
  • **
  • Posts: 66
    • SneakOnTheLot.com
Re: Photon Pickup Manager
« Reply #1 on: July 18, 2013, 12:15:14 PM »
This concept of the Master Player having the only Gold Spawn Manager was flawed.  It works great and spawns gold on all the player's games but there is a major problem.  Every time another player tries to pick up any gold, it crashes and provides the error...

"Cannot call Destroy as we don't control it."

So where can I put this gold spawn manager where any player can pick it up? 

Is there a better way to do this?  Maybe using the Room Properties?

Fletch

  • Junior Playmaker
  • **
  • Posts: 66
    • SneakOnTheLot.com
Re: Photon Pickup Manager
« Reply #2 on: July 18, 2013, 01:25:21 PM »
I guess I could send an RPC call to the master and have it erased from that end but that seems really clunky.

Fletch

  • Junior Playmaker
  • **
  • Posts: 66
    • SneakOnTheLot.com
Re: Photon Pickup Manager
« Reply #3 on: July 18, 2013, 07:55:45 PM »
Okay, so here is my report.

I tried to make the Master client own all the gold prefabs as they were created and then fire off an RPC call to the master, which would destroy that prefab when anyone picked it up.

There are still errors in this model as now when the Master Player disconnects from the game he will take all the gold prefabs with him. 

There must be a cleaner, more simple way. 

I'd love it if room custom properties could do what I'm needing but I don't know if they can. 

Can anyone help me?  Is this what room properties are for or can they be used for this sort of thing?

Fletch

  • Junior Playmaker
  • **
  • Posts: 66
    • SneakOnTheLot.com
Re: Photon Pickup Manager
« Reply #4 on: July 25, 2013, 09:14:07 AM »
Update:

I'm understanding more each day about the photon network setup and structure.  It would really have helped to have a simple diagram that would explain how the system works to begin with. 

The best pickup solution seems to be an FSM gold manager that keeps a running total of the gold currently in game, renaming each coin that is spawned in.

There is also a synched variable that increments with each new gold coin spawned.  This variable is used by each client to rename the new gold coin.

There is an issue with a new player spawning in who's gold coins already in game won't be renamed yet.  Not sure what to do there yet

Fletch

  • Junior Playmaker
  • **
  • Posts: 66
    • SneakOnTheLot.com
Re: Photon Pickup Manager
« Reply #5 on: July 25, 2013, 09:19:31 AM »
Man, if the Photon View RPC Broadcast FSM Event To Player action would just send the right game object to the Get Event Info action this whole issue would be mute.

Check out my other thread about the Photon View RPC Broadcast FSM Event To Player action having a bug in it.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Photon Pickup Manager
« Reply #6 on: July 29, 2013, 05:58:12 AM »
Hi,

 I'll see with Alex if I can inject a given gameObject to override the default behavior of events.

Can you explain why you need to know wo is the sender? I might have a work around for you.

bye,

 Jean

Fletch

  • Junior Playmaker
  • **
  • Posts: 66
    • SneakOnTheLot.com
Re: Photon Pickup Manager
« Reply #7 on: July 29, 2013, 11:24:30 AM »
Thanks for the reply! 

What I have is a gold pickup that instantiates on when the player spawns in. 

With each new player a new gold pickup spawns in.

so if I have 5 players there are now 5 gold coins waiting in the world to be picked up.

The coins are built with a trigger.  When a player tag enters the trigger then is suppose to destroy itself.

Simple in single player mode.  Like most everything else, much more complicated with multiple players on Photon.

The problem is derived from the fact that "Player A" cannot call a destroy game object if "Player B" was the one that instantiated it. 

Okay, so I have to make an RPC call to the owner of the object and tell the owner to destroy that object.

Only problem is that when the picked up coin makes that RPC call, and the owner of the object catches the event info, it doesn't have a clue which object to destroy.

I know there are other ways around this issue.  I could rename every coin that is instantiated as they come into the world and then pass the unique name through to the player as a string... but that seems rather clumsy to me when the event info action literally has a place for what object sent the call in the first place... it just work with RPC calls.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Photon Pickup Manager
« Reply #8 on: July 30, 2013, 06:16:56 AM »
Hi,

 I think you are over thinking this. Your coin should have a fsm or indeed a naming convention, if it's a fsm, then as a player triggers, the coin can check the player and match/deny the process. AND make use of the "is mine" to also match/deny, that is, ONLY player that "is mine" should proceed with checking IF it can pick up that coin.

so the logic id the following:

1: player trigger coins: IS PLAYER MINE? no? --> no action
2: is coin spawned by another player? no? --> no action
3: yeah! let's consume the coin.

I don't think it should be more complicated then that really.

bye,

 Jean

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Photon Pickup Manager
« Reply #9 on: July 30, 2013, 06:18:20 AM »
Hi,

 me again :) actually it's even simpler! the fsm responsible for chekcing coins should be ont he player, AND shoudl be enabled only if mine! very much like user input, it's only an active feature IF the user controls the player. then you only are left with step 2, because that fsm only works when it has to.

bye,

 Jean

Fletch

  • Junior Playmaker
  • **
  • Posts: 66
    • SneakOnTheLot.com
Re: Photon Pickup Manager
« Reply #10 on: July 30, 2013, 09:12:15 AM »
So it the coin isn't owned by the player, what then?  How can you consume it?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Photon Pickup Manager
« Reply #11 on: July 30, 2013, 11:29:25 AM »
Hi,

 That's already down to what you mean by "consuming".  Likely, you will need to destroy the coin itself, and also add 1 to the players coins counter. Because your coin has a network view, it must be destroy using photon, and will disappear from the game for all players.

If you need the coin amount per player to be accessible across the game, on all machines, then add a new custom property to the player, that's how you can synch all your players instances ( for example if all players shows their coins amount as a HUD or something for other players to know).

bye,

 Jean

Fletch

  • Junior Playmaker
  • **
  • Posts: 66
    • SneakOnTheLot.com
Re: Photon Pickup Manager
« Reply #12 on: July 30, 2013, 11:58:36 AM »
Actually, the coin counting is working great.

Let me see if I can explain this a little better.

1) Player A instantiates and his Coin Manager FSM instantiates a coin.  Player A is the owner of that coin.  It has been instantiated by photon and exists on everyone's game.

2) Player B instantiates into the came and his Coin Manager FSM instantiates another coin.  It also has been instantiated by photon and exists on everyone's machine.

Player A can pick up their own instantiated coin without any issues.  Photon destroys the coin and it vanishes from everyone's game.

Here comes the issue.

When Player A tries to pickup the coin that was instantiated by Player B, it fires off an error saying that you can't destroy an object that is owned by another player.

So I have to query Photon to find out who the owner of the coin is and tell them to destroy it.  Only problem is that when Player A tries to tell Player B to destroy it (using the RPC Call) I can't pass the game object to destroy.
« Last Edit: July 30, 2013, 12:07:44 PM by Fletch »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Photon Pickup Manager
« Reply #13 on: July 30, 2013, 04:03:25 PM »
Hi,

 now I get it :) thanks for clarifying.

I actually had to implement this on R.mote, I haven't yet ported it back properly for distribution, the next iteration will feature a RPC action update that will allow you to only fire an event to the same networkView. I need to clean it up still, so hang in there, the solution is already on its way.

Meanwhile, If you want to experiment, I would actually go for coins that are NOT networked. Basically, each player prefab being instanced creates a coin, and then because it's not a networked, you simply have a manager that handles coins deletion as it receives this "global" RPC call. So each running instance has the power to delete a given coin, and the order is sent via RPC when you detect the right combination of player/coin collision. You will have to pass a reference ( likely as a string, or int) to know what coins to delete. Actually, each coins could have this FSm with this RPC event, and each coin can then match the passed arguments with its own reference ( when you instanciate a coin, pass it his reference number to match).

Bye,

 Jean