• 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
Question by vik.vega · Feb 22, 2013 at 03:18 AM · networklagrpcnetworkview

Inaccurate network position

Hello ! I've put together a small barebone client/server implementation for my project (more likely just a study) and i've been reading about the necessity of some degree of prediction on clients, being a necessity on a larger scale of players/informations traveling the network.

What looks strange to me, is that i'm experimenting an annoying amount of latency, with just two Windows clients running on the same machine. the scene is just a plane where the players prefabs (just cubes with a character controller and a ridiculous simple movement script) are instanced.

and this is my code.

 #pragma strict
 
 var server_address:String = "127.0.0.1";
 var server_port:int =25001;
 
 var player_prefab : GameObject;
 var spawnpos : Vector3;
 
     
 function Start () {
 
 }
 
 function Update () 
 {
 
 }
 
 function OnGUI()
 {
     if(Network.peerType == NetworkPeerType.Disconnected)
     {
         if(GUI.Button(new Rect(100,100,100,25),"Start Client"))
         {
             Network.Connect(server_address,server_port);
         }
         
         if(GUI.Button(new Rect(100,125,100,25),"Start Server"))
         {
             Network.InitializeServer(10,server_port,true);
         }
     }    
     
 
     
     else
         {
         if (Network.peerType == NetworkPeerType.Client)
             {
             GUI.Label(new Rect(100,100,100,25),"Client");
             if(GUI.Button(new Rect(100,125,100,25),"Exit"))
                 {
                 Network.Disconnect(150);
                 }
             }
             
             
         if (Network.peerType == NetworkPeerType.Server)
             {
             GUI.Label(new Rect(100,100,100,25),"Server");
             GUI.Label(new Rect(100,125,100,25),"Users : "+Network.connections.Length);
             if(GUI.Button(new Rect(100,150,100,25),"Exit"))
                 {
                 Network.Disconnect(150);
                 }
             }
         
         
         }
             
 }
 
 
 function OnServerInitialized()
 {
 spawnPlayer();
 }
 
 function OnConnectedToServer()
 {
 spawnPlayer();
 }
 
 function OnPlayerDisconnected(player: NetworkPlayer) {
     Debug.Log("Clean up after player " +  player);
     Network.RemoveRPCs(player);
     Network.DestroyPlayerObjects(player);
 }
 
 function spawnPlayer()
 {
     spawnpos = Vector3(Random.Range(-3,3),Random.Range(3,5),Random.Range(-3,3));
     Network.Instantiate(player_prefab, spawnpos, Quaternion.identity, 0);
 
 }

Now, of course the player prefab has the Network View Component attached to it, observing it's transform, and i already tried setting the State Sync from ReliableDeltaCompressed to Unreliable, with no visible benefit. I'm quite sure that in a few tutorials i've seen online(the ones that guided me writing that script, so basically neither one has any kind of movement prediction/smoothing ) people weren't experimenting such a stuttering movement.

Am I missing something ? I see network scripting is not easy pie, so I may be just overstimating the NetworkView component, and should start writing a proper Client side prediction function, maybe something that would lerp player positions from received RPCs, (while calculating a player average delay) but i have no idea where to start without overcomplicate the whole thing, so i'd really appreciate an example :)

thank you for your time

Comment

People who like this

0 Show 0
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

0 Replies

· Add your reply
  • Sort: 

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

get return on networkView.RPC 1 Answer

Server & Client Instantiate 0 Answers

Networking Error! 0 Answers

Network Instaniate,Lag,Bullet Prefab 1 Answer

Can not make RPC calls during Start() 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