• 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 Tyler 2 · Jan 15, 2011 at 05:37 AM · rotate

Looking away from a target?

I know there is a way to make an object rotate to face another object, is there a way to reverse that(make it rotate to look AWAY from the other object)?

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 Bunny83 · Jan 15, 2011 at 06:01 AM 1
Share

Do you need a smooth rotate or an instant rotate? If you want an instant rotate just rotate it with LookAt() towards thr object and then inverse the direction with Quaternion.Inverse()

avatar image yoyo · Jan 15, 2011 at 06:28 AM 0
Share

Or LookAt(target) and then Rotate(0,180,0) should work I think?

3 Replies

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

Answer by · Jan 15, 2011 at 05:42 AM

The easiest way that I can think of would be to create a parent GameObject for the one you want to face away, offset the child 180 degrees from the parent, and then rotate the parent to look at the target object. The overall effect will be that the child will be facing away from the target.

Let me know if you have trouble implementing this (preferably with whatever code you have, so I can adapt it to your needs).


Update:

As I've commented below, if all you want is to once-off snap to a rotation facing exactly away from the target object, you can do as Bunny suggested: use a LookAt() towards the object and then inverse the direction with Quaternion.Inverse(). (rotating 180 around Y won't face you away if the X value is !0)

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 Bunny83 · Jan 15, 2011 at 06:05 AM 0
Share

That sounds a bit strange :D why would you create an GameObject? you only need the position of that (virtual) object. This position have to be deter$$anonymous$$ed via simple vector-addition and then you can use this position as target. Just store it in a Vector3 variable.

avatar image · Jan 15, 2011 at 07:35 AM 1
Share

I read into it that he wanted to track the object, but face away from it. In that case, this is standard fare. Have a read through any number of similar questions with the same solution. It might be that it was adopted as normal practice long ago, but the 'usual' answers you find here tend to be the most efficient, even if not entirely apparent as to why. If all he wants is to snap the direction once-off, then there are simpler solutions (as has been commented).

avatar image
2

Answer by =Aintech= · Aug 06, 2013 at 11:23 AM

Another way to do it, is by using Quaternion.LookRotation. To look away you must first find direction from another object to current object, and then use Quaternion.LookRotation to make object look at this direction.

The way I see it:

 Vector3 direction = object.transform.position - anotherObject.transform.position;
 object.transform.rotation = Quaternion.LookRotation(direction);
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
0
Wiki

Answer by icemacsea · Nov 17, 2012 at 03:06 AM

Here's a solution that utilizes the very handy RotateTo() function in iTween. Actor is the gameObject you want to turn and the obj is the object you want actor to face away from.

`function faceAwayFromObj(actor : GameObject, obj : GameObject, time : float) {

var origRot = actor.transform.rotation;

actor.transform.LookAt(obj.transform);

var rotDest = actor.transform.rotation.eulerAngles.y - 180;

actor.transform.rotation = origRot;

iTween.RotateTo(actor, {"y" : rotDest, "time" : time});

}

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Camera rotation around player while following. 6 Answers

How to Rotate Camera around GameObject (Player) 0 Answers

Make FirstPersonCam follow car direction 1 Answer

Rotate an Object based on shorter angle 1 Answer

3D effect with new UI system 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