- Home /
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?
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
It is just a simple thing, it's not anything that I'll be using frequently.
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;
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.
Oh try
transform.rotation = Quaternion.FromToRotation(Vector3.up, Vector3.forward) * Quaternion.LookRotation(something.position - transform.position, Vector3.up);
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
Follow this Question
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