Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Hoax1 · Jun 21, 2018 at 11:12 PM · physicsrigidbodynetworkingsynchronizationonline

Best way to sync rigidbodies realtime?

I'm making an online game where you're a sphere with a rigidbody and you can only move on the x and y axis. Basically you can add a force to your sphere by holding mouse 1 and the longer you hold the button the greater the force gets applied when you release. My problem is: How do I smoothly sync the rigidbodies realtime and still get the same results on all clients? I've tried just adding a network transform to the player prefab and playing around with the settings but the collisions between the players sometimes acts like one of them hits a wall while the other one keeps slowly rolling like nothing happened. What would be the best way to handle networking in my situation?

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

Answer by Captain_Pineapple · Jun 22, 2018 at 12:11 PM

Hey there,

what you encounter there is one of the fundamental problems in online games...

Think about it like this: You move your objects based on physics. Every player does so on his own client and will handle collisions based on a local version of your game. When you add your network transform the object you sync is like a kinematic body for everyone else. It's an object that can not be moved by someone else since the position updates will only happen in one direction - from owner to everyone else.


This leaves you basically with 2 options:

1: Have a masterclient/server handle all collisions. In this variant everyone will only see a synced version of the players objects that get actually moved at the masterclient/server. To move them you simply send the playerinputs to the masterclient/server and have it apply the forces there. Advantage: Fairly easy to implement. Con: might be laggy for everyone. Even when you are moving your own object.

2: Implement some "Custom collision handling". Whenever you hit other player objects you can calculate the forces that would be applied if the other object was a normal rigidbody in your scene. Then you send a message to the other player to apply forces to his object. Problem is at this point: When you hit his object in your scene, the other player doesn't nessessarily hit's your object in his scene due to network delay. So sometimes this might look like you collide with another player and instead of both players getting hit back due to the collision only one of them might "feel the impact". Advantages: Can be kind of lagfree. Cons: Can lead to weird/unwanted behaviour. Might be more difficult to implement depending on your setup.


This is pretty much how i'd tackel this problem. In case you have more questions about this or something was unclear feel free to ask.

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 Hoax1 · Jun 22, 2018 at 05:44 PM 0
Share

Thanks for the answer! I think I'll go with your first suggestion. So basically everyone will act as monitors watching the server and sending inputs to it? I have figured out how to send the inputs to the host and from the host's perspective the collisions is looking really smooth and good. However I can't seem to figure out how I could make the clients see what the host sees. I tried adding a network transform but that won't work because it changes the results for the host. How would I make the clients see exactly what the host sees (with a little delay or something if necessary)?

Edit: Never$$anonymous$$d I just had to turn off local player authority. Anyway thanks for the help! I've been working on this problem for about three days now and I'm so glad someone helped me :D

avatar image Captain_Pineapple Hoax1 · Jun 24, 2018 at 07:56 AM 0
Share

Cool that it worked! If you are only testing with a few instances on your local machine you might want to test how the delay between input and movement affects the local gameplay before you go any further by "hosting" the game somewhere else for a test.

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

197 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 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 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 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 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 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 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 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 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 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

Network or camera desync or something else? 0 Answers

Multiplayer: The more that join the slower each character is 0 Answers

Networking physics with HLAPI 1 Answer

What's the best method to implement multiplayer on a Billiard game ? 1 Answer

AddForce in multiplayer displays as curved motion 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