Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 Kerl42 · Aug 07, 2015 at 04:10 PM · rotationrotation axislookrotationbottom

Quaternion.LookRotation upwards direction of objects is flipping

Hi everyone,

I currently have a problems with the upwards direction of GameObjects when using Quaternion.LookRotation.

In my game (a 2D game using 3D meshes), I have space ships orbiting a planet. In order to calculate the movement while orbiting, I'm using the Transform.RotateAround() method. When the space ships enter the orbit, I need to align their rotation so that they look into the rigt direction (the one they are flying in during orbit).

When entering orbit, I set the rotation using this code:

 var dummyObj = new GameObject();
         dummyObj.transform.position = unit.transform.position;
         dummyObj.transform.RotateAround(planet.transform.position, Vector3.back, 0.1f);
         var rotation = Quaternion.LookRotation(dummyObj.transform.position - unit.transform.position, Vector3.up);
         unit.transform.rotation = rotation;
         Destroy(dummyObj);

I'm creating a dummy object with the same position my ship has. Then I rotate it a tiny bit around the planet. After that, I let the ship look at the dummy object and delete it afterwards.

In about 50% of the cases this works just fine but in the other cases, the botton of the ship gets turned towards the camera instead of the top. I read loads of other posts about the LookRotation method, but couldn't find an answer which solved my problem...

Thanks in advance for your replies!

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 Glurth · Aug 07, 2015 at 06:21 PM 0
Share

Since you use Vector3.back in your rotate around function, I would think you would want to do the same thing for your LookRotation. The second parameter of LookRotation defines, in this case, the direction that the top of your ship should point. If you want the top of the ship to face out from the screen (z-axis), then use Vector3.back (like you do in your RotateAround). If you want the ship's top to face "away" from the planet, you could use something like ship.position - planet.position.

avatar image Kerl42 · Aug 07, 2015 at 06:51 PM 0
Share

I see your point, but finding the right parameters for Quaternion.LookRotation is not the problem. Vector.up seems to do the trick most of the time (if this is unusual maybe my meshes have a weird orientation).

The problem is that around half of the ships are rotated as I want them to be (with their top pointing to the camera) but the other half is somehow rotated just the other way around (with their bottom pointing towards the camera).

I have the same problem when using LookRotation for traveling of ships between planets where ALL traveling ships flip their orientation (from bottom to top pointing towards camera or the other way around) at a certain coordinate (i call LookOrientation every render cycle there). So i got the suspicion there might be a problem with the first input parameter...?

avatar image Glurth · Aug 07, 2015 at 07:19 PM 0
Share

the first parameter looks ok to me.. it is defining the direction and magnitude of the distance you are about to travel, right? (velocity)

Since you didn't mention it I assume it is else-where in your code and working: but I don't see where you set the new position of the ship.. is it something like:

 unit.transform.position = dummyObj.transform.position

Edit, just to clarify, on which two axis, do the ships move around?

0 Replies

· Add your reply
  • Sort: 

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

Bullet rifling simulation 1 Answer

LookRotation is Returning Weird Values 0 Answers

Rotating On Two Axes Independantly 0 Answers

Rotating about and only one axis 1 Answer

Need help with sprite rotation 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