2d object look at object
Vector3 dir = enemy.position - transform.position;
float angle = Mathf.Atan2(dir.y,dir.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
2d object look at object
Vector3 dir = enemy.position - transform.position;
float angle = Mathf.Atan2(dir.y,dir.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
look at Unity 2D
Vector3 diff = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
diff.Normalize();
float rot_z = Mathf.Atan2(diff.y, diff.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.Euler(0f, 0f, rot_z - 90);
unity 2d looka tt mouse
void Update() {
Vector3 dir = Input.mousePosition - Camera.main.WorldToScreenPoint(transform.position);
float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
unity look at 2d
transform.right = target.position - transform.position; // Works like a CHARM.
2d look at unity
//Look at 2D job using the unity jobs system
struct LookAtJob : IJobParallelForTransform
{
public NativeArray<Vector2> targetPositions;
public void Execute(int index, TransformAccess transform)
{
Vector2 dir = targetPositions[index] - (Vector2)transform.position;
float angle = math.degrees(math.atan2(dir.y, dir.x));
transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us