- Home /
Question by
Abdou23 · Mar 14, 2016 at 08:33 AM ·
lookat2d rotation
2D look at upside down.
I have a patrolling 2D object that I want to look at the target it's moving towards. The problem is sometimes the object turns upside down, when the Z rotation has a high number.
Vector3 dir = target.position - transform.position;
float angle = Mathf.Atan2(dir.y,dir.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
Comment
Answer by ComradeVanti · Mar 15, 2016 at 03:33 PM
add 180° somewhere? Or mabye use Vector3.up instead of forward...? Could work.
I dont really know... post results
Good luck
Answer by tanoshimi · Mar 15, 2016 at 03:58 PM
It's unclear whether your 2D view is top-down or side-on, but it sounds like what you're trying to achieve can be done simply with:
transform.up = target.position - transform.position;
Your answer
Follow this Question
Related Questions
How to define the "front" of an object? 0 Answers
2D tranform.lookAt Problem 1 Answer
Change the face of lookat 2d 0 Answers
Looking at target in 2D 1 Answer