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 Azaldur · Oct 15, 2012 at 05:05 PM · networklerpjitter

Lerp: inconsistent movement(multiplayer related)

Hi, I'm currently making a multiplayer game where players can fire with cannons off a ship, while an other player controls it. The ships position is lerped on the clients from the current position to the next received position. When the players, which do not own the ship and therefore lerp the position of it, shoot with a cannon while the ship is moving, the cannonballs jitter back and fourth. I think the problem would also be noticed if an other ship(or an other object) with the same velocity moves alongside the ship. Thats propably because of dropped network packets and always changing distances Vector3.Lerp got to bypass. Does someone got a similiar problem or knows a solution to avoid this problem? It would be great if you could help me :).

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 JanWosnitza · Oct 16, 2012 at 05:06 PM

At first you should not lerp to the new position but use the new position + velocity to estimate the REAL current position (reduces lag and may also reduce your jitter problem). This will give a position which you could use with Vector3.SmoothDamp to calculate a smoothed display position:

EDIT:

Updates for a single ship should at least contain these values:

  • ship's ID (the way you need it)

  • ship's current position

  • ship's current velocity

  • current round time (= time since battle started)

The client who displays the ship should look similar like this:

 ///////////////////////////////
 // Ship's pseudo declaration:
 var networkPosition = Vector3.zero;
 var networkVelocity = Vector3.zero;
 var networkTime     = Vector3.zero;
 
 var velocity = Vector3.zero;
 
 ///////////////////////////////
 // Position Update received
 
 var networkUpdate = ...;
 
 var ship = getShip( networkUpdate.ID );
 
 ship.networkPosition = networkUpdate.position;
 ship.networkVelocity = networkUpdate.velocity;
 ship.networkTime     = networkUpdate.time;
 
 ///////////////////////////////
 // every frame (Update) for each ship
 
 var ship = ...;
 
 var estimatedPosition = ship.networkPosition + ship.networkVelocity * ( currentRoundTime - ship.networkTime );
 ship.transform.position = Vector3.SmoothDamp( ship.transform.position, estimatedPosition, ref ship.velocity, 0.2f );



Comment
Add comment · Show 11 · 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 Azaldur · Oct 17, 2012 at 10:55 AM 0
Share

Hey Jan, thank you very much for your answer :). That is a similiar solution as I'm working on at the moment. There is one problem: After a longer play session, the positions propably get more and more apart. What to do in this case?

EDIT: Sorry I misread your answer. You use the new position + velocity ins$$anonymous$$d of the current position. Then the problem doesn't appear. I will try your solution, now :)

avatar image JanWosnitza · Oct 17, 2012 at 12:18 PM 0
Share

Good luck! :) Of course you have to multiply the velocity with the elapsed time:

estimatedPositon = networkPosition + networkVelocity * ( Time.time - receivedNetworkTime );

Or much better ins$$anonymous$$d of Time.time have a "roundTime" which should be the same on each client. "receviedNetworkTime" could then be sent with your position + velocity updates for more lag reduction

avatar image Azaldur · Oct 17, 2012 at 12:30 PM 0
Share

Hi Jan, I just tried your solution but it doesn't solve the problem, but made it a little better. I do have a kilometre per hour/miles per hour display on the screen that I think illustrates the problem. While on the screen of the player who controls the ship miles per hour is tacked at for example 35, on the screen of the remote players it goes higher and lower every second around 35. So sometimes its 36,34 oder even 40. And because of that constantly velocity change the objects that are not on the ship, like the cannonballs, "jitters". Do you know what else I could try? What do you mean with receviedNetworkTime? The time since the positon was send? Like: Network.time - info.timestamp?

EDIT: The higher the velocity of the ship, the more the problem appears. When I change the smoothTime to, lets say 0.4, the jitter is sometimes barely noticable. But every few seconds, miles per hour jumps from maybe 35 to even 50 for a second. Then the cannonball makes a huge "step". But I think setting smoothTime higher also leads to a "huge" position difference between the clients and the one player who controls the ship? Because I use photon cloud for the networking part, an authoriative server, where every player gets the data send from the server, is not an option for me. I think when the ping to the server is higher, packets more often get lost or send late, and then miles per hour can make such huge jumps from 35 to 40-50. When I host the server on my computer ins$$anonymous$$d, and don't use the cloud server, the ping is lower and it doesn't make such huge changes.

So in conclusion, I think I need a solution that let me set the smoothTime to maybe 0.5f or 0.6f but also prevent to let the ship position of the clients and the one who owns the ship diverse so much(around 10 units with 0.5). On another note, how would you do the same thing with rotation? Quaternion does not contain a method smoothDamp.

avatar image JanWosnitza · Oct 17, 2012 at 05:37 PM 0
Share

@receivedNetworkTime: exactly what you said, the "round time" on which the position + velocity update was sent.

Do you send ship's velocities over network, too? Or are you calculating it from the position updates?

I updated my post accordingly to this, hope it will clear it up. If your velocity is still "jittering" the most reasonable problem is that the updates over network are corrupted/desialized incorrect!

avatar image JanWosnitza · Oct 17, 2012 at 06:01 PM 0
Share

btw. may you could help him: http://answers.unity3d.com/questions/332399/photon-cloud-doesnt-work-correctly.html ;)

Show more comments

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

Physics + first person camera = jitter? 4 Answers

Camera jitter when using Lerp/Slerp 1 Answer

Lerping orthographic camera size jitters 1 Answer

GUI objects jitter when following "lerped" Gameobject [SOLVED] 1 Answer

Camera Lerp Jitter 0 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