Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Third Party PHOTON SPAWN ISSUE!

Discussion in 'Multiplayer' started by dick, Jun 9, 2015.

  1. dick

    dick

    Joined:
    Sep 6, 2014
    Posts:
    90
    ok when I spawn a player with device 1 into a spot in the world, he spawns there! (which is perfect!). When I spawn another player with device 2 at a different spot, he spawns! (which Is good also!). Now, I can move around and everything but according to player 1, he sees that player 2 is at position 0.0.0. Player 2 sees that player 1 is at position 0.0.0 according to his device. WHY IS THIS?!?! I haven't been able to find an answer is over two months and im so frustrated! Please help i'd gladly appreciate it!! (BTW yes, I have PhotonView attached to both and they are observing the NetworkCharacter which is responsible for sending out its position and receiving others! I will post the NetworkCharacter script and the NetworkManager script, which is responsible for spawning players)
     

    Attached Files:

  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    Your problem is that the spawn happens at 0,0,0?
    Or is your problem that the remote players never move?
    The code looks ok. I didn't run it but NetworkCharacter2.cs seems fine.
    In doubt, put some Debug.Log("methodname") in each of the methods. It's spammy but you can check if every method is called like you expect.
     
  3. JakeBilbe

    JakeBilbe

    Joined:
    Jun 10, 2015
    Posts:
    57
    You need to create a script to send the position and location through Photon and update the players position and rotation, you'll see them at 0,0,0 because your machine isn't entirely sure where they are in real-time unless you synchronize the position and rotation.
     
  4. dick

    dick

    Joined:
    Sep 6, 2014
    Posts:
    90
    @TheBlueInferno yes that's what the Network Character does. On PhotonSerializeview its finds realposition, real rotation of other players and also sends out the same to the server.

    @tobiass The problem is kinda both. If you would have this game on your android device, it would appear as if you are connected to the server and moving around in realtime, however. if another player joins, they see that You are in position 0.0.0 and not moving nor rotating, even if you are! Visa Versa, the device your on sees that a player joined but hes stuck at 0.0.0?

    Also guys I forgot to mention but theres another part of this , a script called PlayerController. The PlayerController Script is responsible for sending movement inputs to the NetworkCharacter script which sends it out to the server. However, im not good at mobile movements sooooo.... this could probably be the problem. I have no idea.
     

    Attached Files:

  5. JakeBilbe

    JakeBilbe

    Joined:
    Jun 10, 2015
    Posts:
    57
    See, if you were controlling both it would be as simple as disabling the movement scripts on instantiate and enable them solely for the player but the few times I've had this issue is due to two things:

    1. The object isn't being instantiated via Photon or is already in the Scene.
    2. Synchronizing Networking movement isn't coded properly.
    Though from what you've posted it's neither, so the only issue could be your Spawn placement. Could you post the code that spawns your player into the server?
     
  6. dick

    dick

    Joined:
    Sep 6, 2014
    Posts:
    90
    ok. its within the the Network Manager. Theres one for void SpawnMyPlayer and void SpawnFreddy
     

    Attached Files:

  7. dick

    dick

    Joined:
    Sep 6, 2014
    Posts:
    90
    Also, I forgot to mention that when I decided to disable the NetworkCharacter script and Make Photon View observe the Transform instead, it works perfectly!! However, viewing the transform is not recommended because it looks so slow and updates not a lot of frames to the server, not very smooth. But the fact it works with transform makes me happy. So when I put the Photon View back to observing the Network Character script(which is supposed to make the character move pretty smoothly across network) it still appears as 0.0.0 :( im guessing theres something with the Network Character script but @tobiass says its fine sooo im stuck now.
     
  8. SeriousBusinessFace

    SeriousBusinessFace

    Joined:
    May 10, 2014
    Posts:
    127
    Have you tried checking if the code is being run at all? Try putting in a few named debug statements, checking each function in turn, and see what happens? ie., "Debug.Log("SomeFunction");" or "Debug.Log("ThisIfStatement");"
     
  9. dick

    dick

    Joined:
    Sep 6, 2014
    Posts:
    90
    Yes, the code is always active with all players. Debug.logs show too, that it is working
     
  10. JakeBilbe

    JakeBilbe

    Joined:
    Jun 10, 2015
    Posts:
    57
    Okay a few things for you to try.

    1) In your script you are getting the ObjectType, try adding a tag instead and adding the GameObjects to the Array through the tag. So replace these:
    Code (csharp):
    1. spawnSpots = GameObject.FindObjectsOfType<SpawnSpot>();
    with these:
    Code (csharp):
    1. spawnSpots = GameObject.FindGameObjectsWithTag("SpawnSpot");
    2) You've also not used the chosen Spawner in your Spawn code:
    Code (csharp):
    1. GameObject myPlayerGO = (GameObject)PhotonNetwork.Instantiate("PlayerController", new Vector3(.5f, 0f, -4f), Quaternion.identity, 0);
    This may be why, you've only set the Bunny to use the SpawnSpot that's been chosen, Freddy and the Player have Vectors set so this could be the reason? I'm not sure if it's been fixed or if it was ever a bug but I remember Photon being a little picky when using Vectors inside an Instantiate call.
     
  11. dick

    dick

    Joined:
    Sep 6, 2014
    Posts:
    90
    @TheBlueInferno ok I will try the first solution and as far as the second one, I had Security and Freddy both spawn at spawn spots originally. just like the line codes in Bunny but when I had them spawn at spawn spots, there was no difference, they ended up at position 0.0.0 (but spawned right at the spawn spot according to that player), so I decided to use Vector3 but theres no difference
     
  12. JakeBilbe

    JakeBilbe

    Joined:
    Jun 10, 2015
    Posts:
    57
    Could you try something for me, spawn both players in and on the Editor drag the players around, do any move? If so which ones and what are they controlled by? (Editor or Game Build).
     
  13. dick

    dick

    Joined:
    Sep 6, 2014
    Posts:
    90
    @TheBlueInferno glad you mentioned that because I tried to move the client around by dragging it but immediately it snap back to their position (0.0.0). The one on the editor is moveable though. Also,i had converted the Network Character script to JS and I noticed it had real position as a editable variable in the inspector! The real position had a x_ y_ z_ space where they all had 0,0,0 (of course). So I changed one of them to 1 and the other client moved! Not only moved but stayed there!
     

    Attached Files:

    • assa.png
      assa.png
      File size:
      16.1 KB
      Views:
      906
  14. dick

    dick

    Joined:
    Sep 6, 2014
    Posts:
    90
    sorry forgot to mention that client = game build
     
  15. JakeBilbe

    JakeBilbe

    Joined:
    Jun 10, 2015
    Posts:
    57
    That's good news! Is it all working now?
     
  16. dick

    dick

    Joined:
    Sep 6, 2014
    Posts:
    90
    Also, I tried your advice with adding a tag instead and adding the GameObjects to the Array but I got two errors:
    (30,41): error CS0117: UnityEngine.GameObject' does not contain a definition for `FindObjectsWithTag'
    (29,43) error CS0117 UnityEngine.GameObject' does not contain a definition for `FindObjectsWithTag'
     
  17. JakeBilbe

    JakeBilbe

    Joined:
    Jun 10, 2015
    Posts:
    57
    I think it might be GameObject.FindGameObjectsWithTag, not entirely sure if this is the same for JS though but it should be.
     
  18. dick

    dick

    Joined:
    Sep 6, 2014
    Posts:
    90
    Unfortuantly, no :( It does the same exact thing >.< I can change the XYZ coordinates however, so when i change them then the person gets spawned to that position, yet, are still unable to move. So the only thing different from this Network Character script (JS) than the original Network Character script (C#) is that there are public coordinates. What the ultimate goal is, is to have those coordinates automatically update by themselves when a joystick is moved without an editor
     
  19. JakeBilbe

    JakeBilbe

    Joined:
    Jun 10, 2015
    Posts:
    57
    Could I see the Synch code for the players? It could be that it's public, but as long as you don't have a script changing them it shouldn't matter.
     
  20. dick

    dick

    Joined:
    Sep 6, 2014
    Posts:
    90
    thx, but now I get two errors:
    Cannot implicitly convert type `UnityEngine.GameObject[]' to `SecuritySpawnSpot[]'
    Cannot implicitly convert type `UnityEngine.GameObject[]' to `FreddySpawnSpot[]'
     
  21. dick

    dick

    Joined:
    Sep 6, 2014
    Posts:
    90
    ok first one is C# and second is of course JS. Youll see what I was talking about when it shows public coordinates on 'real position' in JS. Also, I have Unity 5 if that helps
     

    Attached Files:

  22. JakeBilbe

    JakeBilbe

    Joined:
    Jun 10, 2015
    Posts:
    57
    Okay I think I might have the problem, in your NetworkCharacter you're not only sending your position but controlling it too. Make a new Script JUST for the player Movement. Then have the NetworkCharacter ONLY synchronize your movement. This could be conflicting and messing with your position. Do you also need the exact angle they're facing? Wouldn't the Parents Rotation be enough? I may not be of much use here as I don't really work with JS but I'll try my best. EDIT: Is this script attached to all 3 players, or just the main Player?
     
    dick likes this.
  23. dick

    dick

    Joined:
    Sep 6, 2014
    Posts:
    90
    Its ok , I don't need JS anyway. I just did it to see the differences. And I believe the script "Player Controller" does all of the controlling and player movement . I'll provide it below. Just to let you know, I got this from a person named Quill18 on youtube who goes through a tutorial about making an fps multiplayer with Photon. He gives a link to the complete project (which I downloaded) and tested it out which works perfectly. Now, what I tried to do Is convert the project into mobile since that's what my target platform is but first, I couldn't find out how to make the Joysticks move the player. After a month I found that out but now my problem is, well you know, the players don't match up. I was wondering if you could check out Quill 18's multiplayer tutorial kit and see how I would be able to make that project from PC to Android, if possible.
     
  24. JakeBilbe

    JakeBilbe

    Joined:
    Jun 10, 2015
    Posts:
    57
    Quill18 is very good to watch, to be completely honest I'd advise you to watch his tutorials properly and not copy his code though as his code is designed for a FPS though it will work copying from his exact project you won't understand parts, in the NetworkCharacter you've placed the movement control in the FixedUpdate where you shouldn't be editing movement. I think that's why you're getting these issues because where you're checking if the PhotonView is yours you shouldn't do anything at all but you're running movement code which should be handled in a seperate script. But watch his videos and go through them slowly it's worth the time. :)
     
    dick likes this.
  25. dick

    dick

    Joined:
    Sep 6, 2014
    Posts:
    90
    The game im making is an FPS, it should work correctly. Secondly, the aside annotation within the Fixed Update says"Do nothing -- the character motor/input/etc... is moving us" also, I changed nothing within the fixedupdate so Quill18 had that same line in his project and it worked great.
     
  26. JakeBilbe

    JakeBilbe

    Joined:
    Jun 10, 2015
    Posts:
    57
    Quill18 had a separate script for Movement though is what I'm getting at, you're editing the movement and sending/setting the movement inside the same script so it's bound to cause issues. If you create a separate playerMovement script and have the NetworkCharacter only for synchronizing Position/Rotation it should work.

    Your issue is that something is effecting your position and rotation, this seems like the culprit to be honest as some of the code contradicts with other code in that script. By separating the movement and synchronization it should work fine.
     
    dick likes this.
  27. dick

    dick

    Joined:
    Sep 6, 2014
    Posts:
    90
    Ok so your saying where the void DoLocalMovement within the Network Character script should be deleted? (since im guessing it has something to do with moving).
    Also, the playercontroller script is one of Quill18's separate script that is only for movement. I've edited it for mobile so I was wondering if you could check it out to see if it will properly move the player across the Network. I'll just post the original and then the one I edited. The playercontroller script requires a var in Network character for movement. Ahhhh this is so confusing.Thank you for your patience. ill try it
     
  28. dick

    dick

    Joined:
    Sep 6, 2014
    Posts:
    90
    HOOOOOLY SCHMOKES IT WORKS
     
    tobiass likes this.
  29. dick

    dick

    Joined:
    Sep 6, 2014
    Posts:
    90
    WHAT IS LYFE?
     
  30. dick

    dick

    Joined:
    Sep 6, 2014
    Posts:
    90
    THANKS SOOOOO MUCH
     
  31. JakeBilbe

    JakeBilbe

    Joined:
    Jun 10, 2015
    Posts:
    57
    No worries :) was it because the two scripts were combined?
     
    tobiass likes this.
  32. dick

    dick

    Joined:
    Sep 6, 2014
    Posts:
    90
    No actually, I just deleted the void DoLocalMovement and on my other script I just added some moving things with joystick, I found out that the void DoLoaclMovement within the syncing script didn't have to be deleted. However thanks so much for giving me a hint about "ALL player movement should be done within a separate script", without that, I don't think I would have figured this out!! Its not that they were combined, rather I left some things out!! The script I have below now has ALL the movement controlling the player via joystick, so anyone wanting this can feel free to download it! I cant thank you enough TheBlueInferno !!
     

    Attached Files:

    JakeBilbe likes this.
  33. JakeBilbe

    JakeBilbe

    Joined:
    Jun 10, 2015
    Posts:
    57
    Glad I could of been some help. Though for future reference if you get any issues or problems the best thing to do is go through and add Debug.log("")'s try and figure out where the issue is coming from and there's never any harm in experimenting with code. Good luck on your game! :)
     
    tobiass and dick like this.
  34. dick

    dick

    Joined:
    Sep 6, 2014
    Posts:
    90
    Oh, ok I will certainly try it! Have a nice day
     
  35. programer343

    programer343

    Joined:
    Jan 4, 2017
    Posts:
    1
    Hey @dick ,

    I know it's a bit late but I have the same problem.
    Only 1 player can move and the other is stuck at one place and if I want to move this stuck player, it forces the other one to move. I tried everything but nothing worked. I have two seperate scripts (1.player movement 2. Player Synchronization)