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
1
Question by acosmia · Jan 17, 2015 at 10:19 PM · rotationinstantiationtransform.rotate

How to instantiate an object with a set rotation in one axis, but the other two axes inherited from the parent?

I'm trying to spawn an object with the x axis rotated to 90, but the y and z axes having the same rotation of the spawner. The spawner runs through random items (in this case, it's for decorative flags) and then spawns it.

The reason I need it to be 90 on the x axis is because of how cloths are orientated by default. To have the object up a wall, I need to rotate it. If I instantiate it with transform.rotation, it assumes I also want x, so it gets messy as it can get stuck in walls and the like.

Here's my code; however, it ignores the spawner's y and z and flags always face the same direction!

 #pragma strict
 
 var partsPrefab : Transform[];
 
 function Start () 
 {
     var z = transform.rotation.z;
     var y = transform.rotation.y;
     var rot = Quaternion.Euler(Vector3(90, y, z));
     Instantiate(partsPrefab[Random.Range(0,partsPrefab.Length)], transform.position, rot);
     Destroy(gameObject);
 }
 
 function Update () {
 
 }

It's my first time working with angles like this, though, so I'm a bit lost. Is there any way I can have x = 90, but y and z be transform.rotation?

Any help would be appreciated!

Comment
Add comment · Show 3
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 eich1 · May 02, 2015 at 03:10 PM 0
Share

have you tried Quaternion.identity ins$$anonymous$$d of just "rot" ?

avatar image AppleseedSmoothie eich1 · May 25, 2019 at 12:38 AM 0
Share

He literally said he wants to set the x axis rotation to 90, obviously Quaternion.identity isn't the answer mate

avatar image black843 · May 02, 2015 at 03:37 PM 0
Share

Did u try to put Scripts on ur Sub-Gameobject, that contain that Information of Rotation, etc. in the start or awake function?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by highpockets · May 25, 2019 at 11:02 AM

You are not getting the euler angles when you are setting your z and y floats. You are getting the z and y values of the quaternion. The z and y of a quaternion relate to the axis of a rotation and have nothing to do with euler angles which are in degrees. To get the euler angles of the z and y, you need to use: var z = transform.rotation.eulerAngles.z;.


Having said that though, I would think that Quaternion.LookRotation would give you what you need. You just specify the forward direction (and a hinted up direction for more control if needed) and you're set.

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Accelerating in Turned Direction 2 Answers

transform.Rotate is rotating all axes, why? 0 Answers

Setting rotation parallel to ground 1 Answer

Have Head Bone Rotate with Camera 2 Answers

Flip over an object (smooth transition) 3 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