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
0
Question by smirlianos · Aug 24, 2013 at 12:58 PM · rotationinstantiatepositionlocalcusm rotation

Instantiateon custom rotation doesn't work

Hello,

I made this script to instantiate a projectile on a gameobject A. The script is attached to another gameobject, and object A is a child of the main camera, meaning that it rotates with the camera.

The problem is that the gameobject A has the same rotation on the inspector as it is a child object, and the result is that the projectile gets instantiated with the same rotation every time. How can I fix it?

 var rot = Quaternion.Euler(A.transform.rotation.x, A.transform.rotation.y, A.transform.rotation.z);
         Instantiate(projectile, A.transform.position, rot);
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

2 Replies

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

Answer by robertbu · Aug 24, 2013 at 03:18 PM

'transform.rotation' is a Quaternion...a 4D, non-intuitive construct. The components are not degrees, and you should not use the independent components of a Quaternion unless you understand the math behind them. Unity gives a number of helper functions, so you should not have to use the independent components.

For what you are doing here, you could just:

 var rot = A.transform.rotation;


Or even eliminate 'rot':

  Instantiate(projectile, A.transform.position, A.transform.rotation);
Comment
Add comment · Show 2 · 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 smirlianos · Aug 26, 2013 at 12:52 PM 0
Share

The problem is that I add a float to the y axis of the rotation, as an offset. The rotation of the sphere doesn't change as it's a child object

avatar image robertbu · Aug 26, 2013 at 02:37 PM 0
Share

You can combine rotations:

 Instantiate(projectile, A.transform.position, Quaternion.AngleAxis(25.0, Vector3.up) * A.transform.rotation);
avatar image
1

Answer by perchik · Aug 26, 2013 at 02:43 PM

What @robertbu said is completely correct [as always].

As an alternative, you can use transform.rotation.eulerAngles.x in the same way you are currently doing. This would access the actual euler angles of your rotation, instead of the more abstract quaternion:

 var rot = Quaternion.Euler(A.transform.rotation.eulerAngles.x, A.transform.rotation.eulerAngles.y, A.transform.rotation.eulerAngles.z);
        Instantiate(projectile, A.transform.position, rot);
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

16 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

Related Questions

blocks being placed in an odd way 0 Answers

"Object reference not set to an instance of an Object" 0 Answers

Instantiate Bullet Hole position and rotation, Vector3 issues 1 Answer

Move object on local axis instead of world axis after rotation 0 Answers

instantiating at different Angles? 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