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 PatrickBizenna · Jan 23, 2020 at 10:46 PM · unity 5rotationmultiplayerracing game

Rotation not syncing using Xamp(Apache)

I am updating the rotation and position inside the database and sending it back to both clients . The problem is that the rotation is not working and only the position is updating. So I can see my car moving but always in the same direction as the car does not rotate on the other client.

 IEnumerator moveBox(GameObject box, float x, float y, float rotatex, float rotatey, float rotatez)
     {
 
         //if ( isMoving ) yield break; // exit function
         //isMoving = true;
         if (box.GetComponent<Othersquarecontroller>().isMoving) yield break;
         box.GetComponent<Othersquarecontroller>().isMoving = true;
         Vector3 from = box.transform.position;
         Vector3 to = new Vector3(x, y);
         Quaternion rotation = box.transform.rotation;
         Quaternion torotate = Quaternion.Euler(rotatex, rotatey, rotatez);
         for (float t = 0f; t < 1f; t += Time.deltaTime * 5f)
         {
             box.transform.position = Vector3.Lerp(from, to, t);
             box.transform.rotation = Quaternion.Lerp(rotation, torotate, t);
             yield return null;
         }
         box.transform.position = to;
         box.transform.rotation = torotate;
         box.GetComponent<Othersquarecontroller>().isMoving = false;
     }
 
  IEnumerator getData()
     {
         while (true)
         {
             //checking the url that is being sent
             Debug.Log(url + "?operation=poll");
             //generate the url and send it to the website
             UnityWebRequest www = UnityWebRequest.Get(url + "?operation=poll");
 
             yield return www.SendWebRequest();
 
             if (www.isHttpError || www.isNetworkError)
             {
                 Debug.Log(www.error);
             }
             else
             {
                 //this reads the text from the website
                 //Debug.Log(www.downloadHandler.text);
 
                 //split the data we get from the website.
                 string[] players = www.downloadHandler.text.Split('|');
 
                 //remove the hanging split
                 Array.Resize(ref players, players.Length - 1);
 
                 for (int index = 0; index < players.Length; index++)
                 {
                     Debug.Log(index + " " + players[index]);
                     //split again
 
                     string[] eachplayer = players[index].Split(',');
 
                     //remove the hanging comma
                     Array.Resize(ref eachplayer, eachplayer.Length);
 
                     foreach (string field in eachplayer)
                     {
                         //Debug.Log(field);
                     }
                     //id,name,xpos,ypos,
                     int id = int.Parse(eachplayer[0]);
                     string name = eachplayer[1];
                     float xpos = float.Parse(eachplayer[2]);
                     float ypos = float.Parse(eachplayer[3]);
                     color = eachplayer[4];
                     float rotationx = float.Parse(eachplayer[5]);
                     float rotationy = float.Parse(eachplayer[6]);
                     float rotationz = float.Parse(eachplayer[7]);
 
                     //the \ is an escape string, this line removes the single quote from the nicknames in the database if they have single quotes
                     name = name.Trim('\'');
 
                     if (GameObject.Find(eachplayer[0]) == null)
                     {
                         if (eachplayer[4] == "Red")
                         {
                             string urllcar2 = "http://127.0.0.1/game/AssetBundles/car2";
                             WWW www2 = new WWW(urllcar2);
                             while (!www2.isDone)
                                 yield return null;
                             car = www2.assetBundle;
 
                             mycar = car.LoadAsset("car2") as GameObject;
                             otherplayer = Instantiate(mycar, new Vector3(xpos, ypos), Quaternion.identity);
 
                             otherplayer.GetComponentInChildren<TextMeshPro>().text = name;
 
                             otherplayer.name = eachplayer[0];
 
                             otherplayer.AddComponent<Othersquarecontroller>();
                             if (car != null)
                             {
                                 car.Unload(false); //scene is unload from here
                             }
                         }
 
                         if (eachplayer[4] == "Green")
                         {
                             string urll = "http://127.0.0.1/game/AssetBundles/car";
                             WWW www1 = new WWW(urll);
                             while (!www1.isDone)
                                 yield return null;
                             car = www1.assetBundle;
                             mycar = car.LoadAsset("car") as GameObject;
                             otherplayer = Instantiate(mycar, new Vector3(xpos, ypos), Quaternion.identity);
                             otherplayer.GetComponentInChildren<TextMeshPro>().text = name;
 
                             otherplayer.name = eachplayer[0];
 
                             otherplayer.AddComponent<Othersquarecontroller>();
                             if (car != null)
                             {
                                 car.Unload(false); //scene is unload from here
                             }
                         }
                         if (eachplayer[4] == "Yellow")
                         {
                             string urllcar1 = "http://127.0.0.1/game/AssetBundles/car1";
                             WWW www3 = new WWW(urllcar1);
                             while (!www3.isDone)
                                 yield return null;
                             car = www3.assetBundle;
                             mycar = car.LoadAsset("car1") as GameObject;
 
                             otherplayer = Instantiate(mycar, new Vector3(xpos, ypos), Quaternion.identity);
                             otherplayer.GetComponentInChildren<TextMeshPro>().text = name;
 
                             otherplayer.name = eachplayer[0];
 
                             otherplayer.AddComponent<Othersquarecontroller>();
                             if (car != null)
                             {
                                 car.Unload(false); //scene is unload from here
                             }
                         }
                     }
                     else
                     {
                         if (eachplayer[0] != loadedplayer.name)
                         {
                             //update other player position
                             otherplayer = GameObject.Find(eachplayer[0]);
                             // otherplayer.transform.position = new Vector3(xpos, ypos);
 
                             StartCoroutine(moveBox(otherplayer,xpos , ypos, rotationx, rotationy, rotationz));
                         }
                     }
                 }
             }
         }
     }
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

Answer by Bunny83 · Jan 24, 2020 at 03:22 AM

Well, your code does only include the reading code. Have you actually debugged the 3 angles? Have you inspected your database what values you got there? Are you sure that you actually read and store the eulerAngles of the objects in your database and not the 3 imaginary components x, y and z of the quaternion? We can not answer those questions. You should have included what you have already tried, what values you get back (Debug.Log?!)


You also want to use Quaternion.Slerp instead of Quaternion.Lerp because Lerp does not perform a constant speed animation. Slerp (spherical linear interpolation) does rotate at a constant speed and also avoids some other issues.

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

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

change rotation using WheelCollider.steerAngle 0 Answers

Unet: Loading Screen 2 Answers

CAR ROTATING HELP 2 Answers

multiply Score on Collision not working? check my code plz 2 Answers

My Obstacle Rotations Are Not Correct 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