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 nastasache · Sep 03, 2012 at 08:18 PM · rotationnetworkingmouseanglerpc

Rotation via RPC and wrong result angle

Hi there,

I have a problem with sending transform rotation using RPC.

Basically, I try to get the mouse input for Y axe when rotating the clone on the client, and rotate the clone on server using this value via RPC.

The rule it's apparently working, but the final rotation angle on the server is a bit (more or less) different from the rotation on client. Why?

Here is the essential part of code I use:

 /**
 // Transform components


 // --------------------
 // CharacterMotor.js
 // --------------------
 
 var getUserInput : boolean = true; // false on Server, true on Client
 
 var rotateInput : float;
 
 function Update () {
     
     if (getUserInput) { 
     
         rotateInput = Input.GetAxis("Mouse X"); 
     
     }

     // rotateInput by RPC on Server, by Input on Client
     transform.Rotate(0, rotateInput, 0); 
 
 }
 
 
 // --------------------
 // NetworkController.js // active on Client only 
 // --------------------

 var rotateInput : float;
 var lastRotateInput : float;
 
 var targetController : CharacterMotor; // (above, assigned)
 
 function Update() {
 
     rotateInput = Input.GetAxisRaw("Mouse X");
 
     if (rotateInput != lastRotateInput) {
         
         Debug.Log("Send rotation: " + rotateInput); 
         
         networkView.RPC("SendRotation", RPCMode.Server, rotateInput);
     
     }
     
     lastRotateInput = rotateInput;
 }
 
 
 @RPC
 function SendRotation(rotateInput : float) {
     
     Debug.Log("Receive rotation: " + rotateInput); 
     
     targetController.rotateInput = rotateInput;
 
 }



Start/Stop rotation on Client. Debug.Log reports looks ok:

 Send rotation: 0.2,  Receive rotation: 0.2
 
 Send rotation: 0.9, Receive rotation: 0.9
 
 Send rotation: 0.3, Receive rotation: 0.3
 
 Send rotation: 0,25, Receive rotation: 0.25
 
 Send rotation: 0.05, Receive rotation: 0.05
 
 Send rotation: 0, Receive rotation: 0

But:

Final Y angle reported on Client = 25.5

Final Y angle reported on Server = 24.75

What is reason of this difference?

Thanks in advance,

Iulian

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 asafsitner · Sep 04, 2012 at 07:00 AM

The difference is probably due to latency.

I believe you'll want to use state synchronization rather than RPC for this, however.

This is not exactly what RPC were meant for.

Comment
Add comment · Show 5 · 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 nastasache · Sep 04, 2012 at 08:58 AM 0
Share

Thanks for answer, asafsitner. I don't know if I can use state synchronization. I tried to extend TPS-Auth Unity example. The problem with using state synchronization there is that the owner of the script it's server, so that the states sync serialization are send by the server. But the client it's initiating movement. The client must send info. I think this is reason the keyboard inputs (I just added mouse inputs) are send by RPC to the server ins$$anonymous$$d of state sync, then server made the requested transformation and use sync state with corrections goal only. I am missing how to initiate state sync for rotation from the client to the server since client is not owner of the script. On the another hand, I see RPC for positions looks having not a problem with latency.

avatar image asafsitner · Sep 04, 2012 at 11:22 AM 0
Share

What I'll do in this case is have a separate object that handles input from the client.

The client will own that object and synchronize keyboard state to the server (I'd personally use a `BitArray`).

The server will move the character on it's end (taking into account latency from the client), and synchronize the position/rotation back to the client. In this case the server owns the character.

The client on it's end smooths the movement received from the server, with correction based on latency as well.

avatar image nastasache · Sep 04, 2012 at 11:36 AM 0
Share

Thanks, asafsitner. I didn't tried syncing using separated object for the inputs. I will try.

avatar image nastasache · Sep 05, 2012 at 07:26 PM 0
Share

Thanks again, asafsitner! Separate objects handling inputs with state syncronization it's working like a charm.

avatar image asafsitner · Sep 05, 2012 at 07:45 PM 0
Share

Hey, that's great to hear! Networking can be a real headache sometimes. :)

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

8 People are following this question.

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

Related Questions

3D Turret Rotation 0 Answers

How to calculate angles and apply to rotate an object. 1 Answer

Interpolation of player's position over RPC calls 2 Answers

Character not rotating 1 Answer

Get angle from mouse direction? 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