How do I teleport all other players to a transforms position?

Options
Hello,

I wish to make it so that when 1 player enters an area, all other players are teleported to his position.

I have made a flat cube that I intend for to act as a trigger.

I have the connection set up and have done everything in accordance with this guide up to and with part 7:
https://doc.photonengine.com/en-us/pun/current/tutorials/pun-basics-tutorial/player-networking#beams

I use Unity 5.3.5f1

Here is a screenshot of the script i try to get working.

http://i.imgur.com/29dj7A2.png

What do I do from this point?

Answers

  • Hi Doh09,

    the current source code you provided has a problem. It is only executable when the master client triggers the collision. When you want to make your described scenario work for all players, you need to remove the PhotonNetwork.isMasterClient condition.

    To achieve what you want to have, you can use RPCs or RaiseEvent, to send the position of the collision / trigger to other clients. When other are processing the call locally, they can set their positions to the one they received before.

    Also you may want to check the difference between OnCollisionEnter(...) and OnTriggerEnter(...), in your case OnTriggerEnter seems to be the way to go.
  • Doh09
    Options
    A little update, I may have found a partial solution, I have managed to get the players to move to the correct location with the code shown in the image below. This has worked in a test with 2 players, both locally and over network.

    http://i.imgur.com/arsePnU.png

    I am not sure how well coded this is, whether or not I am making risky coding.

    One issue that persists though, is that even though i set the animators value to 0 as to make the player not use his run animation, he continues to use it.

    @Christian_Simon , you were right about the MasterClient check, this has been removed in the now altered code.
  • Took some time, but now I understand your approach. This might be some way to solve this, but it is really hard to catch it, since you are more or less evaluating what others did.

    You mentioned that the player keeps running. Is that just on remote clients or does this affect the local player too? In the first case you might check / implement the OnPhotonSerializeView(...) function, since anim.SetFloat("Speed", 0); is just a local call and maybe not synchronized at all.
  • Doh09
    Options
    It affects the local player too.

    The animators should be synchronized, as I have put them in the list of observables in the Photon View, as can be seen in the picture below.

    http://imgur.com/RlvBLY5

    When one person runs I can see it on the other persons screen.

    I think I have figured out what is the reason for the issue, but I am not sure how to solve it yet.

    When I teleport the players, they are all teleported to the exact same coordinates of the checkpoint. To make them stop running I also set their running destination to the new coordinate, but they are pushed outwards from the point as they cannot stand on top of each other. (Movement is by mouse clicking)

    So suddenly you have 2 people, both pushed x distance from the point they want to be, and they begin running towards point x but cannot reach it because they block each other.

    One solution I see is to make the checkpoint they are teleported to, have child objects that are basically spawn locations for players, but i would hate to lock the players in like that.

    Another possibility is to make players be able to walk through each other, which could be a game setting you can turn on and off, but I really would like the players NOT to be able to walk through each other as it would disrupt elements of the game.

    If you have any suggestions I'm all ears, I'll ponder more about it :-)
  • Doh09
    Options
    Actually I will try go for the spawn location fix.
  • If they are blocking each other you might try working with distances, so that when they are close enough to a certain point, they stop moving and don't need to reach the target position it at all. Something like
    if (Vector3.Distance(transform.position, targetPosition) <= 1.0f)
    {
        // Stop
    }