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 Kiloblargh · Dec 22, 2012 at 06:15 PM · networkinginputtimerpclatency

Networking noob; how do I sync / time input with RPCs?

I already have it so the first player to start the game registers with the MasterServer as the host and the second player finds the game and connects as a client, and then when either player hits "play," both instances of the game start at the same time. I guess my question is "Now what?" so I'll try to give my own answer to that and see if someone else has a better one...

The game pieces move in discrete units every game "tick". (~ 0.5sec) The player can press keys (or onscreen buttons) to choose a direction at any time in the cycle, but when the 'metronome' function invokes they move in whatever direction the most recent input said to, or forward if there was no input that time. This seems like it should be one of the easiest control styles to make multiplayer, but it is my first such effort.

My main problem is what to do right at the end of the timer period when a different key is pressed within the client's time limit but lag makes the call get there after the server has already recorded the previous keypress as the 'final' one.

Also not sure what to send with the RPC (could it just be one byte?) and when to send it. My idea was that locally there would be a lastKey variable that updates immediately each time there was an input. Then two RPC functions that just ping-pong back and forth constantly regardless whether lastKey has changed (player 1 RPCs a function on player 2 that first updates the theirKey variable on player 2's game to player 1's lastKey and saves the timeStamp, then player 2 RPCs the same function on player 1. So each player's theirKey is no older than the latency time from lastKey, but no duplicate messages are sent.

Is that all wrong? Am I missing something important? It seems like there are just a lot more ways to do something that are wrong when it comes to multiplayer communication.

( I did read the docs and whatever else I could find to read but it feels like the Unity team wants people to figure out how to use the networking on their own.)

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
Best Answer

Answer by raoz · Dec 22, 2012 at 10:30 PM

If you do care about security, than this is the way to go, however, if you don't care about security, than you could have the input calculated on the client and the positions being sent back and forward. The problem with your solution is that it might get out of sync on the 2 ends.

Comment
Add comment · 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

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

10 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

Related Questions

RPC or Synchronization ? 1 Answer

How to send timestamp via RPC so it was relative to the receiver? 1 Answer

How to measure network packet delay? 0 Answers

Countdown issue with Networking 0 Answers

RPCMode.All Question 1 Answer


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