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 J-R-Wood · Aug 30, 2018 at 11:57 PM · arrayscript.quaternion

Array of Quaternions based of Array of GameObjects (NOT WORKING)

I am trying to get the rotation of every object in an array of gameobjects and put it in an array of Quaternions but when i do this it puts them in the Quaternion array as mere fractions of what the rotations were supposed to be.

The code that i thought would do this is

             for (int i = 0; i < OBJList.Length; i++)
             {
                 OBJloc[i] = OBJList[i].transform.position;
                 OBJrot[i] = OBJList[i].transform.rotation;
             }

Based off a few google searches but i must of misunderstood something because this doesn't provide me with the rotation of each object in the array while it does work just fine for getting the Vector3 of each object.

Comment
Add comment · Show 6
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 JVene · Aug 31, 2018 at 12:10 AM 0
Share

How have you deter$$anonymous$$ed that the OBJrot[ i ] entries are a fraction of what is expected?

avatar image J-R-Wood · Aug 31, 2018 at 12:19 AM 0
Share

See attached.

1.png (109.5 kB)
2.png (134.5 kB)
avatar image J-R-Wood · Aug 31, 2018 at 12:32 AM 0
Share

I was getting a list of objects during runtime and then my idea was that after storing all the data about the objects in an array i would save the array which consisted of a Int,Vector3,Quaternion and then be able to load it after restarting the game, now this is just me testing it all but here is the following code i was using...

avatar image J-R-Wood · Aug 31, 2018 at 12:33 AM 0
Share

This is where i got all the info to save: using UnityEngine; using System.Collections;

 public class SaveOBJTESTwithtag : $$anonymous$$onoBehaviour
 {
     public GameObject PREFAB;
     public GameObject $$anonymous$$aster;
 
     public GameObject[] OBJList;
     public Vector3[] OBJloc;
     public Quaternion[] OBJrot;
     public Vector7[] Pack;
     void Start()
 {
 
         OBJList = GameObject.FindGameObjectsWithTag("OBJ");
         OBJloc = new Vector3[OBJList.Length];
         Pack = new Vector7[OBJList.Length];
         OBJrot = new Quaternion[OBJList.Length];
 }
     void Update ()
     {
         if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.S)) {
             $$anonymous$$aster.Send$$anonymous$$essage("Ending", Pack); 
         }
         if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.C)) {
 
             OBJList = GameObject.FindGameObjectsWithTag("OBJ");
 
             for (int i = 0; i < OBJList.Length; i++)
             {
                 OBJloc[i] = OBJList[i].transform.position;
                 OBJrot[i] = OBJList[i].transform.rotation;
             }
             for (int i = 0; i < OBJloc.Length; i++)
             {
                 //Pack[i].location = OBJloc[i];
                 Pack[i].location.x = OBJloc[i].x;
                 Pack[i].location.y = OBJloc[i].y;
                 Pack[i].location.z = OBJloc[i].z;
             }
             for (int i = 0; i < OBJrot.Length; i++)
             {
                 //Pack[i].rotation = OBJrot[i];
                 Pack[i].rotation.x = OBJrot[i].x;
                 Pack[i].rotation.y = OBJrot[i].y;
                 Pack[i].rotation.z = OBJrot[i].z;
             }
         }
 
         if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.B)) {
             for (int i = 0; i < Pack.Length; i++) {
                 Instantiate (PREFAB, new Vector3 (Pack [i].location.x, Pack [i].location.y, Pack [i].location.z), Pack[i].rotation);
             }
         }
 
 
 
     }
     void LoadData(Vector7[] OldPackData)
     {
         Pack = OldPackData;
     }
 
 }
avatar image J-R-Wood · Aug 31, 2018 at 12:34 AM 0
Share

This is where i made the struct that i guess i needed in order to store the vector3 and quaternions in Binery Format using UnityEngine; using System.Collections; [System.Serializable] public class Vector7 { public int Item; public Vector3Serializer location; public SerializableQuaternion rotation; } [System.Serializable] public struct Vector3Serializer { public float x; public float y; public float z; public void Fill(Vector3 v3) { x = v3.x; y = v3.y; z = v3.z; } public Vector3 V3 { get { return new Vector3(x, y, z); } } } [System.Serializable] public struct SerializableQuaternion { public float x; public float y; public float z; public float w; public SerializableQuaternion(float rX, float rY, float rZ, float rW) { x = rX; y = rY; z = rZ; w = rW; } public static implicit operator Quaternion(SerializableQuaternion rValue) { return new Quaternion(rValue.x, rValue.y, rValue.z, rValue.w); } public static implicit operator SerializableQuaternion(Quaternion rValue) { return new SerializableQuaternion(rValue.x, rValue.y, rValue.z, rValue.w); } }

Show more comments

1 Reply

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

Answer by JVene · Aug 31, 2018 at 01:15 AM

The rest isn't formatted as code, so I haven't read that part, but this:


   for (int i = 0; i < OBJrot.Length; i++)
              {
                  //Pack[i].rotation = OBJrot[i];
                  Pack[i].rotation.x = OBJrot[i].x;
                  Pack[i].rotation.y = OBJrot[i].y;
                  Pack[i].rotation.z = OBJrot[i].z;
              }



Doesn't copy all of the parameters inside the Quaternion. The commented line would copy a reference to the complete quaternion, and I haven't dealt with any other issues that may still be at work here, but Quaternions have a w parameter that isn't being copied, and that would produce incomplete results.

Comment
Add comment · Show 1 · 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 J-R-Wood · Aug 31, 2018 at 01:23 AM 0
Share

Perfect! after i changed it to

         for (int i = 0; i < OBJrot.Length; i++)
         {
             Pack[i].rotation.x = OBJrot[i].x;
             Pack[i].rotation.y = OBJrot[i].y;
             Pack[i].rotation.z = OBJrot[i].z;
             Pack[i].rotation.w = OBJrot[i].w;
         }

Everything worked just fine.

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

109 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

Related Questions

Add two radius on the same shader 1 Answer

List of scripts? 2 Answers

How to get an array of transforms and move GameObject for certain duration to that transforms list 0 Answers

Isolation of different vertices on a mesh 2 Answers

Having trouble accessing a unique instance of a dynamically generated script... 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