• 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 CHull · Nov 10, 2014 at 03:04 PM · c#movementnetworkingrpcsmooth

Smooth Movement with RPC's

Hey,

I'm working on a University project in which processing is distributed via RPC's. I have a server and two clients and have gotten to a stage in which the clients see two boxes and have two buttons on their screen. Each button will move a box, however the physics for box one occurs on the server and the position is then sent to the clients and with box two the physics is carried out on client one with the results of the button press being sent out to other clients. Below is the code I have, however on the machines in which the physics processing isn't taking place the box movement is very twitchy and not smooth. It's almost as though it teleports to the position. I realise I am just sending the position of the box causing it to look jittery but i don't know of any other way. How can i smooth out the movement of the boxes on the machines that don't do the processing?

 if(GUILayout.Button("Move Box One"))
             {
                        networkView.RPC("SendCubeOneMoved", RPCMode.Server, null);
             }
 if(GUILayout.Button("Move Box Two"))
             {
                 if (localPlayer == target)
                 {
                     cube2.rigidbody.AddForce(new Vector3(0,500,0));
                     cube2Pos = cube2.transform.position;
                     networkView.RPC("SendCubeTwoPosition", RPCMode.Others, cube2Pos);
                 }
             }
             break;    
         }
     }
 
     [RPC] 
     void SendCubeOneMoved()
     {
         cube1.rigidbody.AddForce(new Vector3(500,0,0));
         cube1Pos = cube1.transform.position;
         networkView.RPC("SendCubeOnePosition", RPCMode.Others, cube1Pos);
     }
 
     [RPC]
     void SendCubeOnePosition(Vector3 cube1Pos)
     {
         cube1.transform.position = cube1Pos;
     }
     
 
     [RPC]
     void SendCubeTwoPosition(Vector3 cube2Pos)
     {
         cube2.transform.position = cube2Pos;
     }
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 DavidMann · Nov 23, 2014 at 02:45 AM

First off. Don't use RPCs for position updates--that's an inappropriate use and it will lead to you pain. You ought to look up some of the unity networking tutorials to learn the proper way to do this. Try looking here: http://docs.unity3d.com/Manual/net-StateSynchronization.html and here http://docs.unity3d.com/ScriptReference/Network.OnSerializeNetworkView.html

Now, to answer your question:

What you want to do in interpolate between the positions provided by the net code. Look up Vector3.Lerp.

Basically, when you get a position update, you begin lerping the position of the thing towards the new position. Then, when you get the next nework update with position, you update the current position to the LAST position received and being lerping the position towards the NEW position. The time you want it do do this movement in is approximately the time it takes between newrok updates.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Making a bubble level (not a game but work tool) 1 Answer

Can I use Rpc Calls and Commands on the same object? 0 Answers

[Error] RPC function undefined in IRRELEVANT file? 0 Answers

How can I create a smooth rigidbody2d movement? 1 Answer

unity c# RPC 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