Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Boki83 · Dec 06, 2018 at 08:53 AM · rotationnetworkinggimbal-lockdedicated-server

Rotation sync over network on dedicated server

This was probably asked a dozen of times, but I can't seem to find the answer anywhere.

I have a dedicated server for a space game written in C# console application. The problems that I'm facing is the synchronisation of GameObject rotations. I'm suspecting the issue being related to gimbal lock, but I am not sure.

Here I have my player movement/rotation controller:

 public class PlayerMovement : MonoBehaviour {
     [SerializeField] float maxSpeed = 40f;
     [SerializeField] float shipRotationSpeed = 60f;
 
     Transform characterTransform;
 
     void Awake()
     {
         characterTransform = transform;
     }
 
     void Update()
     {
         Turn();
         Thrust();
     }
 
     float Speed() {
         return maxSpeed;
     }
 
     void Turn() {
         float rotX = shipRotationSpeed * Time.deltaTime * CrossPlatformInputManager.GetAxis("Vertical");
         float rotY = shipRotationSpeed * Time.deltaTime * CrossPlatformInputManager.GetAxis("Horizontal");
 
         characterTransform.Rotate(-rotX, rotY, 0);
     }
 
     void Thrust() {
         if (CrossPlatformInputManager.GetAxis("Move") > 0) {
             characterTransform.position += shipTransform.forward * Speed() * Time.deltaTime * CrossPlatformInputManager.GetAxis("Move");
         }
     }
 }


This script is applied to my character object which is a ship. Note that the character object has a child object which is the ship itself and has fixed rotation and position that do not change. When character has moved/rotated I send the following to the server: position(x, y, z) and rotation(x, y, z, w).

Now here is the actual script that receives network packet information and updates the other players in game:

 public class CharacterObject : MonoBehaviour {
     [SerializeField] GameObject shipModel;
 
     public int guid;
     public int characterId;
     public string name;
     public int shipId;
 
     Vector3 realPosition;
     Quaternion realRotation;
 
     public void Awake() {
     }
 
     public int Guid { get { return guid; } }
     public int CharacterId { get { return characterId; } }
 
     void Start () {
         realPosition = transform.position;
         realRotation = transform.rotation;
     }
     
     void Update () {
         // Do nothing
     }
 
     internal void LoadCharacter(SNCharacterUpdatePacket cuPacket) {
         guid = cuPacket.CharacterGuid;
         characterId = cuPacket.CharacterId;
         name = cuPacket.CharacterName;
         shipId = cuPacket.ShipId;
         realPosition = new Vector3(cuPacket.ShipPosX, cuPacket.ShipPosY, cuPacket.ShipPosZ);
         realRotation = new Quaternion(cuPacket.ShipRotX, cuPacket.ShipRotY, cuPacket.ShipRotZ, cuPacket.ShipRotW);
         UpdateTransform();
 
         Instantiate(Resources.Load("Ships/Ship1/Ship1"), shipModel.transform);
     }
 
     internal void UpdateCharacter(SNCharacterUpdatePacket cuPacket) {
         realPosition = new Vector3(cuPacket.ShipPosX, cuPacket.ShipPosY, cuPacket.ShipPosZ);
         realRotation = new Quaternion(cuPacket.ShipRotX, cuPacket.ShipRotY, cuPacket.ShipRotZ, cuPacket.ShipRotW);
         UpdateTransform();
     }
 
     void UpdateTransform() {
         transform.position = Vector3.Lerp(transform.position, realPosition, 0.1f);
         transform.rotation = Quaternion.Lerp(transform.rotation, realRotation, 0.5f);
     }
 }

Do you see anything wrong with the code ?

My experience with 2 players in game is the following: When I start the game with two players they spawn at the same location (0,0,0) and same rotation (0,0,0). Lets say that The other player is rotating continuously around the X-axis only. What I am experiencing is:

  1. First 90 deg. of rotation it renders fine.

  2. Next 180 deg. of rotation the object stays in place

  3. The last 90 deg. of rotation renders fine

In the first version I did not send the 'w' value of Quaternion, but then added it in the second version and it did not help. Note that there is no restrictions in rotation and users can rotate endlessly in all directions. Btw the positioning works fine.

I might not understand Quaternions fully, but I thought that they had a purpose in avoiding the gimbal lock issue.

Any help would be appreciated.

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

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

168 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 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 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 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 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 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 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

Reverse rotations problems... 2 Answers

Camera Bounce when Orbiting too Qucikly 0 Answers

Importing from blender adds gimbal locks 0 Answers

How do I sync Client bullet rotation on network? 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