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)?

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);

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).


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)

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;


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

actor.transform.rotation = origRot;

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