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 Urre · Feb 07, 2012 at 05:44 PM · movementmultiplayerpositioninterpolationsmoothing

Networked position interpolation implementation (not Dead Reckoning)?

I spent most of today attempting to find a nice short description of how to implement interpolated positions for a networked object, without much success. It seems only mentioned here and there, but I couldn't find any descriptions which didn't make my head hurt. I finally managed to make an implementation which I believe could be cleaned up a lot, but here's the jist of it:

 curAngle = Mathf.SmoothDampAngle(curAngle, newNetAngle, ref tempvelF, prevRotDiff);
 myTransform.rotation = Quaternion.Euler(0, curAngle, 0);
 if (newNetAngle != oldNetAngle)
 {
     prevRotDiff = Time.time - prevRotStamp;
     prevRotStamp = Time.time;
     oldNetAngle = newNetAngle;
 }
 myTransform.position = Vector3.SmoothDamp(myTransform.position, newNetPos, ref tempvelV, prevPosDiff);
 if (newNetPos != oldNetPos)
 {
     prevPosDiff = Time.time - prevPosStamp;
     prevPosStamp = Time.time;
     oldNetPos = newNetPos;
 }

It moves the object (in this case a player) just the right amount until it recieves a new update. What I'm wondering is what SmoothDamp and SmoothDampAngle actually does mathwise here? I tried doing the math myself but failed.

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

Answer by Owen-Reynolds · Feb 07, 2012 at 06:38 PM

MoveTo and SmoothDamp both do about the same thing, but the Smooths try to add an extra accelerate phase in front, and a decel in back. Sort of like how a spline turns a straight line into an S-curve.

MoveTo moves or spins at a constant speed. That can look robotic, as it snaps to full speed, then snaps to a stop. But, say you have an animation which already incorporates realistic movement. Then you want MoveTo, to run it evenly.

In your case, the original object is probably being moved "realistically" by physics, so you don't need to extra smoothing (it makes the copy object "heavier") and can use MoveTo.

Comment
Add comment · Show 4 · 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 Urre · Feb 07, 2012 at 07:36 PM 0
Share

Nice, I'll take a look at that tomorrow. What does the math behind $$anonymous$$oveTo look like though? I understand the concept, it seems like such a trivial thing but for some reason I couldn't figure it out.

avatar image Urre · Feb 07, 2012 at 08:25 PM 0
Share

I took a quick look at $$anonymous$$oveTowards (which I assume is what you meant), which seems to expect a speed value rather than time it takes to reach goal. Not really following how it's supposed to work, but in any case, this speed vs time is a pretty significant difference for me. If I would've been able to figure out the speed based on old & new positions and the timestamps I could probably have lived without SmoothDamp. What to do? :S

avatar image Owen-Reynolds · Feb 08, 2012 at 12:39 AM 1
Share

$$anonymous$$oveTowards is pretty much just val+=speed; if(val past target) val=target; SmoothDamp (AFAI$$anonymous$$,) does the same, but also ramps up and down the speed. If you note, the time is only a guide. I guess you could set $$anonymous$$oveTowards speed = distance/wantedTime (speed is in $$anonymous$$/S.)

This is for dropped packets? The set-up confuses me. Unity will normally invisibly set transform.rotation to the new angle. It looks like you're sending infrequent RPCs yourself, and making it smooth at the expense of a lag. But I haven't done enough Unity-Network stuff to say anything useful.

avatar image Urre · Feb 08, 2012 at 07:31 AM 0
Share

Yes Unity would automaticly set the angle and/or position if I let it, but the problem lies in the fact that packets are sent at a lower interval than the client's framerate (15 is the default sendrate, whereas I generally have like 90fps), so I need to smooth the positions inbetween the updates. At first I had it immediately update both position and angle, but it was choppy just as expected.

As for dropped packets, dead reckoning handles that a tad better since it keeps moving the object even if it didn't recieve any update, and corrects itself once it does. This interpolated solution rather just waits at the current position if it didn't recieve an update as expected, until it gets a new update, by which time it starts smoothing towards the new position. It works quite well as long as packets aren't frequently lost. A packet here and there won't be all that bad. This variant is somewhat more common than dead reckoning actually, since it's so much simpler to implement (which is why I felt so frustrated about not figuring it out at first).

distance/wantedTime was indeed the magic I was after. Thanks a lot!

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Interpolating the motion of a camera moving from one node to another 1 Answer

Smoothing Network Movement with OnSerializeNetworkView 0 Answers

Network Trasnform Interpolation Factor 2 Answers

Lock player position 1 Answer

Why is Input.GetAxisRaw() not returning whole numbers when using a joystick? 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