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 GameSlayerGS · Apr 29, 2013 at 02:15 PM · gameobjectlookatface

Change LookAt Face

Is it possible to somehow change the face of a GameObject that looks towards another GameObject, from what I can tell it's normally the positive Z face, is it possible to say, make it be the positive Y face?

Comment
Add comment · Show 2
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 Loius · Apr 29, 2013 at 03:43 PM 0
Share
  • is forward, though. you're going to keep running in to problems if you try to use some other axis as the forward element. if you're just doing a one-shot thing with +Y though, go for it

avatar image GameSlayerGS · Apr 29, 2013 at 05:35 PM 0
Share

It is just a simple thing, it's not anything that I'll be using frequently.

1 Reply

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

Answer by whydoidoit · Apr 29, 2013 at 03:17 PM

Yes just multiply transform.rotation by the Quaternion representing the change you require:

    transform.LookAt(something);
    transform.rotation = Quaternion.FromToRotation(Vector3.up, Vector3.forward) * transform.rotation;
Comment
Add comment · Show 3 · 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 GameSlayerGS · Apr 29, 2013 at 05:34 PM 0
Share

Well that works, now maybe I'm getting something wrong, but the object that's looking is below the object it's looking at, so the top of the object is facing the target object. When the target object has coordinate that's negative (noting that the Y coordinate doesn't change) the looking object turns completely upside down. Any idea why? Is this one of the sort of problems that I may have by not using the forward vector (+Z) for looking? I can change the whole thing around a bit to be able to use the +Z vector for looking, but it'd be a pain at this point.

avatar image whydoidoit · Apr 29, 2013 at 06:27 PM 0
Share

Oh try

  transform.rotation = Quaternion.FromToRotation(Vector3.up, Vector3.forward) * Quaternion.LookRotation(something.position - transform.position, Vector3.up); 
avatar image GameSlayerGS · May 01, 2013 at 05:20 PM 0
Share

Well that seems better, but it still flips over when the position of the target object has a negative coordinate. To give more detail: that script is in an object named "Base". The object it's looking at is located 100 above (as in Y+) the "Base" object, and is named "Target". The Target object moves around in a sliding motion where only the X and Z coordinates change. If I need to at this point I wouldn't $$anonymous$$d too much flipping the "Base" object so it's Z+ face is up, but then I'd have to change some other things too, that although I know how to make those changes, would take a little while.

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

15 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

Related Questions

How to rotate a gameobject over time to face another 1 Answer

Rotate to Center of Screen 2 Answers

Look At Target? 2 Answers

Camera rotate around sphere centre 2 Answers

using Contains(gameObject) to find and destroy a gameObject from a list 2 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