Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by verenion · Jan 27, 2015 at 01:55 PM · networkingphotonmoving platform

Photon / Networking Multiple players, Multiple moving platforms

Driving me mad!

Issue The game has multiple moving platforms that players are "teamed" together on. E.g. Red team on one platform, Blue team on another. Players can spawn on either team, and when the platforms are not moving, the networking works fine. A player can then request to take over control of the platform and can move their own teams platform around.

If two players are on the same platform, when the platform is moved, the 'remote' players stutter around and jump - because the platform is moving, but the Lerping of the remote position is not quite correct. The players are not parented to anything, which could be a solution - but the players should be able to move from their own platform to the other, which makes it even more tricky to accomplish.

Possible Solutions

  • One solution is to use some sort of clever network extrapolation to smooth out the position of the players, relative to the platform that they are one. I'm not sure if this would work very well though.

  • Parent each player to their respective platform - this should solve the stuttering of players on the same platform, but then the players on the other platform will have issues. If the player moves from one platform to the other, simply change the parent. Not sure if this can be done seamlessly.

  • Maybe there is a more obvious solution I am missing?

  • Give up and become a bin man?

I'm not looking for someone to write a whole system obviously, but any help would be appreciated.

Each player has the following simple network smoothing :

 // Update is called once per frame
     void Update()
     {
         if (!photonView.isMine) {
                         transform.position = Vector3.Lerp (transform.position, this.correctPlayerPos, Time.deltaTime * 8);
                         transform.rotation = Quaternion.Lerp (transform.rotation, this.correctPlayerRot, Time.deltaTime * 8);
         } 

     }

     void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
     {

         if (stream.isWriting)
         {
             // We own this player: send the others our data
             stream.SendNext(transform.position);
             stream.SendNext(transform.rotation);
             
         }
         else
         {
             // Network player, receive data
             this.correctPlayerPos = (Vector3)stream.ReceiveNext();
             this.correctPlayerRot = (Quaternion)stream.ReceiveNext();
         }
     }

Thanks in advance!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by jpthek9 · Jan 27, 2015 at 04:35 PM

You could child the players to a platform and send the local position instead of the global position. Then you use the same smoothing technique except on transform.localPosition. If you want to change platforms, simply detach the child on OnCollisionExit and attach to child to the new platform on OnCollisionEnter.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image verenion · Jan 27, 2015 at 04:46 PM 0
Share

This is similar to what I tried. I'll try again tonight to see if I can get a working prototype. Will this affect jumping, as jumping would cause OnCollisionExit to be fired.

avatar image jpthek9 · Jan 27, 2015 at 06:11 PM 0
Share

All localPosition is is the position relative to the parent. If the parent stays still, absolutely nothing happens. If the parent moves right, the unit will move right as much as the parent did. If you jump, make sure you detach the child by calling

transform.parent = null;

so you don't move with the platform while in the air. Then when you finish jumping, simply attach the object again. i.e.

 void OnCollisionExit (Collision col) //jumping or falling off
 {
 if (col.transform == transform.parent)
 transform.parent = null;
 }
 
 void OnCollisionEnter (Collision col) //landing on the platform
 {
 if (col.transform.tag == "Platform")
 transform.parent = col.transform
 }

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Photon Network syncing the transform of a moving platform 0 Answers

[Photon]Player vs. Player Collision 0 Answers

Correct way to design turn based multiplayer using Photon Unity Networking. 0 Answers

how do i apply damage to objects other that the player 1 Answer

Photon Unity Network - Refresh/Tickrate 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges