playMaker

Author Topic: Photon RPC setup. Please help me!  (Read 1005 times)

sandEboy

  • Playmaker Newbie
  • *
  • Posts: 39
    • GraspTech
Photon RPC setup. Please help me!
« on: December 13, 2020, 10:48:03 AM »
I've been trying to figure out this problem for days now.

I can't get the RPC function to spawn a bullet from the correct player. I have a standard fps setup, the player moves around on the XZ axis. The camera is parented to the player and looks around. A gun is parented to the camera and an empty object called muzzle is parented to the gun. This object stores it's position in global  vector3 to be used with the spawn bullet function in the RPC Shoot Global event.

The problem is when I test the game it not only double spawns the bullet prefab. It also only shows it being spawned from other players who didn't didn't shoot. Unless there are no other players in the game it spawns correctly.

The attached image shows the gun function fsm.

LordHorusNL

  • Beta Group
  • Full Member
  • *
  • Posts: 226
Re: Photon RPC setup. Please help me!
« Reply #1 on: December 13, 2020, 05:07:23 PM »
It's been a while since I've done anything with multiplayer but here's my advice.

If you're using PUN2 the RPC is being sent to ALL Photon Views in your scene, not just the Photon View attached to the Game Object you think of as the "receiver"

So when you send the "RPC Shoot" event, it gets received by the FSM on ALL the players and not just the one that is actually firing the shot.

So what you need to do is this. Before sending the "RPC Shoot" event, you need to retrieve the Photon View ID from the Network Object firing the shot and send this ID along with your Vector3 as a string variable over the network.

You use "Build String" and "Split String" actions for this I believe.

Then on every instance of the FSM that receives the "RPC Shoot" event you just retrieve the Photon View ID from the string and compare it against the ID of that Game Object's Photon View.

So if this ID matches the ID of the player firing the shot, you instantiate the bullet. If not you do nothing.

In PUN2 and I believe also in PUN Classic it's your responsibility to figure out what script or FSM needs to act on the received RPC. Photon just sends it to all Photon Views.

Hope that makes sense.