Answers for "unity sprite disappears when using transform.lookat"

C#
0

unity sprite disappears when using transform.lookat

// Do not use "transform.LookAt" for 2D 
// Instand use something similar to this

public static void LookAt2D(this Transform transform, Vector2 target)
{
    var direction = target - (Vector2)transform.position; // Get the direction
    var angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg; // Convert to angle
    transform.rotation = Quaternion.AngleAxis(angle - 90, Vector3.forward); // Finally rotate the GameObject
}
Posted by: Guest on October-07-2020

Code answers related to "unity sprite disappears when using transform.lookat"

C# Answers by Framework

Browse Popular Code Answers by Language