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
2
Question by defterniko · Feb 15, 2013 at 04:50 PM · rotationjavascriptgameobject

using a custom rotation in "Instantiate"

I'm calling a GameObject to load at a specific point. I originally called it like this:

building = Instantiate(farmingPlot, farmPosition, transform.rotation );

However I need it to rotate 45 degrees in the x axis. Therefore I tried calling it like this:

building = Instantiate(farmingPlot, farmPosition, (transform.rotation.x-45,transform.rotation.y,transform.rotation.z) );

This is not working though. Does anyone know how I can do this?

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

4 Replies

· Add your reply
  • Sort: 
avatar image
12

Answer by robertbu · Feb 15, 2013 at 05:12 PM

You don't want to be using the x,y,z and w values of a rotation directly unless you really understand Quaternions. In fact, I'm surprised this compiled. Use Quaternion.Euler() instead:

 building = Instantiate(farmingPlot, farmPosition,  Quaternion.Euler(Vector3(45, 0, 0)));

This will give an absolute rotation of 45 degrees. If you want it relative like you have it, you can add transform.eulerAngles.y to the value.

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
avatar image
5

Answer by Orami · Aug 25, 2015 at 02:53 PM

I wanted to update this since I came across it if you put the Vector3 call in the Quaternion.Euler call your code will not compile. Just drop the Vector3() portion off and your golden. See documentation: http://docs.unity3d.com/ScriptReference/Quaternion.Euler.html

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
avatar image
4

Answer by abrakadabra · Mar 14, 2016 at 10:48 AM

I was looking for my problem too, and what I wanted to just rotate 90 degrees when I look just straight to sprite. It was Z instead of Y axis.

 Instantiate (fish, spawnPosition, Quaternion.Euler(new Vector3(0, 0, -90)));

alt text

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
avatar image
1

Answer by MakoBec · Oct 02, 2014 at 12:44 PM

var spawnTemp = Instantiate(prefab, gameObject.transform.position, Quaternion.Euler(270, 0, 0));

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 yogurt1989 · Dec 07, 2017 at 06:30 AM 0
Share

That did the trick, thanks a lot!

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

14 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

Related Questions

Rotate an Object 1 Answer

Link object rotation to its parent 1 Answer

Rotating an object in position 2 Answers

How do you flip a card with smooth rotation? 1 Answer

Trying to rotate and move a gameobject through JavaScript, help? 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