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 HolBol · Oct 10, 2013 at 05:12 PM · networkingmouselooksynchronizationfirst person controller

First Person Networking

So I'm teaching myself networking- and I'm using the First Person Controller. It's not ideal, I know, but this is a learning experiment. I can host a game, and have clients join. And here comes the issue:

I can have players moving- but their rotation from the mouselook scripts on the FPController asset doesn't update- so from each character's perspective, everybody is looking one direction. How would I go about synchronising those values, when the networkView component can only monitor one other component?

I'm using an adaptation of the paladinstudios networking tutorial for my networking code, which is below (integrated into the FPSInput Standard Asset).

 private var motor : CharacterMotor;
 private var controller : CharacterController;
 private var lastSynchronizationTime : float = 0.0;
 private var syncDelay : float = 0.0f;
 private var syncTime : float = 0.0f;
 private var syncStartPosition : Vector3 = Vector3.zero;
 private var syncEndPosition : Vector3 = Vector3.zero;
 // Use this for initialization
 //var pcamera : GameObject;
 
 function Awake () {
     motor = GetComponent(CharacterMotor);
     controller = GetComponent(CharacterController);
     }
 
 // Update is called once per frame
 function Update () {
 
     if (networkView.isMine) {
         
         InputMovement();
         
     } else {
     
         SyncedMovement();
     }
 
 }
 
 function OnSerializeNetworkView(stream : BitStream, info : NetworkMessageInfo) {
 
 var syncPosition : Vector3 = Vector3.zero;
 var syncVelocity : Vector3 = Vector3.zero;
 
     if(stream.isWriting) {
             
             syncPosition = transform.position;
             stream.Serialize(syncPosition);
             
             syncPosition = controller.velocity;
             stream.Serialize(syncVelocity);
             
             }
             
             else {
             
                 stream.Serialize(syncPosition);
                 stream.Serialize(syncVelocity);
         
                 
                 syncTime = 0f;
                 syncDelay = Time.time - lastSynchronizationTime;
                 lastSynchronizationTime = Time.time;
      
                 syncEndPosition = syncPosition + syncVelocity * syncDelay;
                 syncStartPosition = transform.position;
                 //syncEndPosition = syncPosition;
                 
             }
 }
 
 function SyncedMovement() {
     
     syncTime += Time.deltaTime;
     transform.position = Vector3.Lerp(syncStartPosition, syncEndPosition, syncTime / syncDelay);
 
 }
 
 function InputMovement(){
     // Get the input vector from kayboard or analog stick
     var directionVector = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
     
     if (directionVector != Vector3.zero) {
         // Get the length of the directon vector and then normalize it
         // Dividing by the length is cheaper than normalizing when we already have the length anyway
         var directionLength = directionVector.magnitude;
         directionVector = directionVector / directionLength;
         
         // Make sure the length is no bigger than 1
         directionLength = Mathf.Min(1, directionLength);
         
         // Make the input vector more sensitive towards the extremes and less sensitive in the middle
         // This makes it easier to control slow speeds when using analog sticks
         directionLength = directionLength * directionLength;
         
         // Multiply the normalized direction vector by the modified length
         directionVector = directionVector * directionLength;
     }
     
     // Apply the direction to the CharacterMotor
     motor.inputMoveDirection = transform.rotation * directionVector;
     motor.inputJump = Input.GetButton("Jump");
 }
 
 // Require a character controller to be attached to the same game object
 @script RequireComponent (CharacterMotor)
 @script AddComponentMenu ("Character/FPS Input Controller")

Finally, the players are spawned with a simple network instantiate when they join.

Any ideas on how I'd keep everything (like horizontal mouselook on the player, vertical mouselook on the camera, and movement) all in one place so it all synchronises at once?

Comment
Add comment · Show 4
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 sdgd · Oct 10, 2013 at 05:29 PM 0
Share

did you try it doing this way?

give total controll and everything to player and sending the data only to other players like position and rotation of your movement?

so that objects are kind with no controlls at all they are kinda "dead" but moved by networking

avatar image HolBol · Oct 10, 2013 at 06:02 PM 0
Share

Is this not what this already does?

avatar image HolBol · Oct 10, 2013 at 06:18 PM 0
Share

Wait- do you mean I should choose an authoritative server system ins$$anonymous$$d? I'm just looking into that, and it does look promising.

avatar image HolBol · Oct 13, 2013 at 06:54 PM 0
Share

So nobody knows?

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.

Follow this Question

Answers Answers and Comments

17 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

Related Questions

Photon Unity Networking (Viking Demo) Error: Argument is out of range. 1 Answer

Animation with root motion synchronization in multiplayer 1 Answer

Multiplayer client and server aren't talking to each other properly after changing scenes 0 Answers

Check if RPC was received or acknowledged by the client 1 Answer

Syncing Animations on Child Objects in UNET 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