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 jonhillman · Sep 08, 2011 at 11:10 PM · rotationjavascriptarrayquaternion

new Array storing rotations

I have a scenario where I am iterating through gameObjects and storing their locations and rotations in arrays like this:

     for(var base in bases){
                     if(base.name == "type1"){
                         baseLocations1.push(base.transform.position);
                         baseRotations1.push(base.transform.rotation);
                     }
                     if(base.name == "type2"){
                         baseLocations2.push(base.transform.position);
                         baseRotations2.push(base.transform.rotation);
                     }
                 }

The issue I am seeing is that rotations are all stored as (0,0,0,1)...however, if those rotations are read into a builtin array like this:

 gameManager.baseLocations1 = baseLocations1.ToBuiltin(Vector3);
                 gameManager.baseRotations1 = baseRotations1.ToBuiltin(Quaternion);
                 gameManager.baseLocations2 = baseLocations2.ToBuiltin(Vector3);
                 gameManager.baseRotations2 = baseRotations2.ToBuiltin(Quaternion);

then the rotations are stored correctly.

Can anyone tell me why I'm seeing this? I am trying to upload the Arrays as joined strings (using Array.join), then ultimately pull them down somewhere else and use them to place objects on a map. The upload/download works perfect, it's just that the format of the rotations is somehow getting zeroed out.

Comment
Add comment · Show 1
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 jonhillman · Sep 09, 2011 at 04:14 AM 0
Share

to clarify, a Debug.Log(base.transform.rotation) inside the for loop within the if statement shows the same thing, where the rotation is (0,0,0,1). And, like I said before, if this rotation is then stored in a builtin array, which explicitly types the data as Quaternion, the rotation then appears correctly (as viewed in the Editor Inspector). I can't see how the incorrect rotation of (0,0,0,1) in the JS Array gets to being correct in the builtin Array. Is the lack of typing in the JS Array the issue?

1 Reply

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

Answer by CHPedersen · Sep 09, 2011 at 06:27 AM

This had me scratching my head for a little while when I first started using Unity, too. It happens because the vector's ToString-method truncates the coordinates in Debug.Log when you pass in the entire vector/Quaternion at a time. Try to pass in the coordinates individually, like Debug.Log("x: " + base.transform.position.x + ", y: " + ... etc ) and you'll see that the coordinates aren't zero, you just weren't seeing the decimals before.

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 jonhillman · Sep 09, 2011 at 05:19 PM 0
Share

Thanks so much! I am now pushing to the Array like this, and it works great:

baseRotations1.push("(" + base.transform.rotation.x +","+base.transform.rotation.y+","+base.transform.rotation.z+","+base.transform.rotation.w+")");

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Rotation along the x-axis to that player can turn around? 1 Answer

Gradual Rotation of Character from 2 Axis Input Sources 0 Answers

Smooth rotation in 90° increments 0 Answers

Euler angle problems with rotation limit script 3 Answers

Need help converting Euler-based rotation to Quaternion-based (gimbal lock). 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