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 Sasstraliss · Jul 17, 2013 at 03:08 PM · multiplayerinterpolationlan

Basic Multiplayer Entity Interpolation over LAN

Hi everyone.

Right off the bat, I've already read several tutorials as well as Valve's documentation on interpolation. It wasn't terribly helpful, and all of the examples I've found on interpolation are over my head.

I'm after a multiplayer game over LAN (8 or less players). It will be LAN, and thus the ping will be very low. I'd like the movement of each player from each clients perspective to be smooth, as by default it's a bit jittery.

My code is as follows. Two simple scripts. One global network management script, and a player movement script attached to the player object that is instantiated for each player that joins. Each player sees each others player movement as jittery. I've been unsuccessful at basic interpolation.

Because I'm doing this for LAN, I'm assuming the interpolation can be much more basic and less complicated. I tried changing the sendRate from 15 to something higher, but that didn't seem to make any difference at all. Even values such as 500 didn't make a difference.

All of the various links to the networking examples published by Unity are dead. I can't find any official interpolation examples.

The code I have so far is as follows.

NetworkManager.cs

 using UnityEngine;
 using System.Collections;
 
 public class NetworkManager : MonoBehaviour 
 {
     public GameObject playerPrefab;
 
     void StartServer()
     {
         Network.InitializeServer(32, 25000, false);
         Network.sendRate = 15;
         Debug.Log("Server initialized, sendRate: " + Network.sendRate);
     }
 
     void ConnectToServer()
     {
         Network.Connect("127.0.0.1", 25000, "");
     }
 
     void OnGUI()
     {
         if (GUI.Button(new Rect(10, 10, 100, 20), "Start Server"))
             StartServer();
 
         if (GUI.Button(new Rect(200, 20, 100, 20), "Join Game"))
             ConnectToServer();
     }
 
     void OnConnectedToServer()
     {
         Network.Instantiate(playerPrefab, new Vector3(0, 0.5f, 0), Quaternion.identity, 0);
     }
 
     void OnDisconnectedToServer()
     {
         Network.Destroy(playerPrefab);
     }
 }



PlayerMovement.cs

 using UnityEngine;
 using System.Collections;
 
 public class PlayerMovement : MonoBehaviour 
 {
     private float x = 0;
     private float z = 0;
     public Vector3 currentPos;
 
     void Update () 
     {
         if (networkView.isMine)
         {
             currentPos = new Vector3(x, 0.5f, z);
             if (Input.GetKey("left"))
                 x -= 1f * Time.deltaTime;
             if (Input.GetKey("right"))
                 x += 1f * Time.deltaTime;
             if (Input.GetKey("down"))
                 z -= 1f * Time.deltaTime;
             if (Input.GetKey("up"))
                 z += 1f * Time.deltaTime;
             transform.position = currentPos;
         }
     }
 
     void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
     {
         Vector3 pos = Vector3.zero;
         if (stream.isWriting)
         {
             pos = Vector3.Lerp(pos, currentPos, Time.time);
             stream.Serialize(ref pos);
         }
         else
         {
             stream.Serialize(ref pos);
             currentPos = Vector3.Lerp(pos, currentPos, Time.time);
         }
     }
 }
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
Best Answer

Answer by appels · Jul 24, 2013 at 07:28 PM

Changing the send rate of the networkView isn't the way to go. An example of interpolation can be found here: GraduallyUpdateState.cs I'm not saying it's a good example but it's a start. If you want to understand what needs to be done, read this: Fast-paced multiplayer

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.

Follow this Question

Answers Answers and Comments

16 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

Related Questions

how to put manually a name when i start a host with Network Manager? (LAN) 1 Answer

How can I check if a particular IP is a server? 1 Answer

Network Trasnform Interpolation Factor 2 Answers

How to implement online multiplayer in a simple 1v1 game? 2 Answers

absolute beginner Multiplayer 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