playMaker

Author Topic: How to spawn items/projectiles in Pun2?  (Read 1763 times)

paradiseprime

  • Full Member
  • ***
  • Posts: 106
How to spawn items/projectiles in Pun2?
« on: October 28, 2021, 02:24:15 AM »
I am trying to spawn a weapon and then equip it to my player.

I tried Instantiate Scene Object but that errored out.

Tried Pun Instantiate and that also errored out.

Tried Create Object and that worked but it is not in the right spot on other player's screens.

I tried to add a Photon Transform View but it still did nothing. What else am I missing and what is an efficent way of spawning many projectiles?

paradiseprime

  • Full Member
  • ***
  • Posts: 106
Re: How to spawn items/projectiles in Pun2?
« Reply #1 on: October 28, 2021, 09:51:03 PM »
So after some more digging, the way I am currently trying to go about this is by:

1. Giving every player a projectile spawner of their own
2. When the Local Player spawns a projectile, he sends an event to all his other copies on other local player's sides projectile spawner
3. The projectile spawned has a "Is Mine" and only the Local Player has the actual controls. Every other projectile is basically empty but follows the original projectile.

The issue I am having is when trying to send an event to ONLY other projectile spawners belonging to me is that only Photon View RPC Broadcast Fsm Event works and ONLY if I broadcast all.

This would be fine if it only broadcasted on all other clones of the original player that spawned the projectile but it sends an event to Everyone meaning if 2 players spawn a projectile at the same time, one of them isnt going to work. How can I get past this?

Is there a way to send an event to all other non local player clones?

heavygunner

  • Sr. Member
  • ****
  • Posts: 344
Re: How to spawn items/projectiles in Pun2?
« Reply #2 on: October 30, 2021, 02:35:25 PM »
Have a projectile spawn point called "gun" for example.
When you fire, do this.

Get position and rotation of child object "gun"
then, convert vector variables to string.
then build string in this format
nickname+psotion[string]+rotation[string] and save it on new string variable. eg : RPC Message

Broadcast rpc to all.

Have a common game manager object in scene. that will receive the message and split that string and store it on array.

nickname useful for define who is fired the projectile.
then, convert those string to vector.
then use action create object. usig the vectors.

now, all players should see the projectile. no need to add transform view since it spawned to everyone

paradiseprime

  • Full Member
  • ***
  • Posts: 106
Re: How to spawn items/projectiles in Pun2?
« Reply #3 on: October 31, 2021, 11:10:43 PM »
Thank you so much. This has been plaguing me for a while now.