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 murkertrer · Jan 13, 2015 at 09:22 PM · rotationnetworkingrpcinterpolation

Interpolation of player's position over RPC calls

Hi guys!

So I'm trying to establish my first game that utilizes the Network, so please bear with me :p

I'm trying to set a Server with full authority. The clients, in order to make movements, pass the information of motion unto the server, who then communicates the changes made, towards the clients.

I think I have done this correctly, but now I have run into the problem of jittering. I have tried somethings to make the jitter less prominent through modification of the timestep, send rate and assigning function to the LateUpdate.

But I guess that there is no way to make the movement smooth if I don't do interpolation.

So I guess the question is this>

If I'm using the following RPC to move the player (In this case a RotateAround), how could I do interpolation?

Is this an incorect view to update the players position? Is there a simpler way

I dont really understand all the things that are already written on the internet, :((

Any help much appreciated :D, Its hard being self taught : /

 var target : Transform; 
 var haveControl : boolean = false;
 
 
 function Update()
 
 {
     if(haveControl)
     {
         if(Network.isClient)
         {    
     
             var MouseY : float = Input.GetAxis("Mouse X");    
             networkView.RPC("MoveMouseToServer", RPCMode.Server, MouseY);    
         }
     }
 }
 
 function LateUpdate () {
     
     if (Network.isServer)
     {
         networkView.RPC("updatePlayer", RPCMode.OthersBuffered, transform.position);
         networkView.RPC("updatePlayerRot", RPCMode.OthersBuffered, transform.rotation);    
     }
 }
 
 @RPC
 function MoveMouseToServer(MouseY : float){
 
     transform.RotateAround(target.transform.position, Vector3.up, MouseY*3);
 }
 
 @RPC
 function updatePlayer(playerPos : Vector3){
     transform.position = playerPos;
 }
  
 @RPC
 function updatePlayerRot(playerRot : Quaternion){
      transform.rotation = playerRot;
  }
  

Any Ideas?

Is there a way to do something like Lerp, the actual position, with the information that is being received from the server when they do>

     networkView.RPC("updatePlayer", RPCMode.OthersBuffered, transform.position);
     networkView.RPC("updatePlayerRot", RPCMode.OthersBuffered, transform.rotation);    

Is there a way to set a variable with the information that is being received via RPC?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by jpthek9 · Jan 13, 2015 at 09:45 PM

Have a variable LastReceive representing the last time you got the positional update then a LastReceiveDelta representing the last time it took to get another positional update. Also have the LastPosition which is the last positional update you're interpolating from and store the new positional update in NewPosition. Then...

 void Update()
 {
 transform.position = Vector3.lerp(LastPosition, NewPosition,
 (Time.time - LastReceive) / LastReceieveDelta);
 }

 [RPC] PositionalUpdate(Vector3 UpdatedPos)
 {
 LastPosition = NewPosition;
 NewPosition = UpdatedPos;
 LastReceiveDelta = Time.time - LastReceive;
 LastReceieve = Time.time;
 }

Comment
Add comment · Show 6 · 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 murkertrer · Jan 13, 2015 at 10:18 PM 0
Share

Where should I call this?

[RPC] PositionalUpdate(Vector3 UpdatedPos)

avatar image jpthek9 · Jan 13, 2015 at 10:46 PM 0
Share

I'd say PositionalUpdate is equal to UpdatePlayer in your script. Just use @RPC ins$$anonymous$$d of [RPC]

avatar image murkertrer · Jan 15, 2015 at 10:25 PM 0
Share

Hey! You set me on the right track! thanks! I got a smooth movement when I apply this scripts into objects, but for some reason, it is not the case when I add it to a camera, any idea why this is the case?

avatar image jpthek9 · Jan 15, 2015 at 11:05 PM 0
Share

Are you setting the camera's position the exact same way?

avatar image murkertrer · Jan 19, 2015 at 04:19 AM 1
Share

Here is my working code, for the use of the people, implemented into a WASD movemnt (and not a Rotate Around). I changed some of the math because it was causing Nan and negative values. Perhaps due to differencesin the execution order and between the prodecuals calls?

 #pragma strict
 //Unit relatedd components and characteristics
 var director : Transform;
 var haveControl : boolean = false;
 
 //Speed $$anonymous$$anagement
 var val : float = .5;
 var speed : int = 1;
 var JumpStrenght : float = 600;
 
 
 //Positional Update in the server
 var LastPosition : Vector3;
 var NewPosition : Vector3;
 var LastReceived : float;
 var LastReceivedDelta : float;
 var IntervalNet : float;
 var LastReceivedRot : float;
 var LastReceivedDeltaRot : float;
 var IntervalNetRot : float;
 var LastRotation : Quaternion;
 var NewRotation : Quaternion;
 var ServerPosition : Vector3;
 var ServerRotation : Quaternion;
 
 
 function Update(){
     if(Network.isServer){                  
         ServerPosition = transform.position; 
         ServerRotation = transform.rotation;
         networkView.RPC("PositionalUpdate", RPC$$anonymous$$ode.AllBuffered, ServerPosition);
         networkView.RPC("PositionalUpdateRot", RPC$$anonymous$$ode.AllBuffered, ServerRotation);            
     }
         
     if(haveControl)
     { 
     
         if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.W))
         {networkView.RPC("$$anonymous$$oveSphereDF", RPC$$anonymous$$ode.Server, val);}
         if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.S))
         {networkView.RPC("$$anonymous$$oveSphereDF1", RPC$$anonymous$$ode.Server, val);}
         if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.A))
         {networkView.RPC("$$anonymous$$oveSphereDR", RPC$$anonymous$$ode.Server, val);}             
         if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.D))
         {networkView.RPC("$$anonymous$$oveSphereDR1", RPC$$anonymous$$ode.Server, val);}
         if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Space))
          {networkView.RPC("JumpSphere", RPC$$anonymous$$ode.Server, val);}
     }     
      if (Network.isClient)
      {    
          if(!System.Single.IsNaN(IntervalNet)){            
              transform.position = Vector3.Lerp(LastPosition, NewPosition, LastReceivedDelta);    
          }
          
          if(!System.Single.IsNaN(IntervalNetRot)){            
              transform.rotation = Quaternion.Lerp(LastRotation, NewRotation, LastReceivedDeltaRot);    
          }    
     }
 }    
 
 
 @RPC
 function PositionalUpdate(ServerPosition : Vector3){
      LastPosition = NewPosition;
      NewPosition = ServerPosition;
     LastReceivedDelta = Time.time - LastReceived;
     LastReceived = Time.time;
     
     //transform.position = Vector3.Lerp(LastPosition, NewPosition, LastReceivedDelta);
 }
  
Show more comments
avatar image
1

Answer by murkertrer · Jan 16, 2015 at 02:43 PM

You were right! It was not. My camera had the same script, but it was a child of an object, who had itelf to deal with RPC calls!

Thanks for the help buddy :D

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

26 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Rotation via RPC and wrong result angle 1 Answer

How To Deal With Lingering Prefabs in Multiplayer Scene ? 0 Answers

Which is better: NetworkView or RPC? 1 Answer

RPC method gets called before Start(). 0 Answers

UNET Rotation of Child transform 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