728x90
public void Set(Vector3 pos, Vector3 dir)
{
transform.position = pos;
transform.rotation = Quaternion.AngleAxis(Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg, Vector3.forward);
}
// dir = (target.pos - pos).normalize
protected void LookAt2D(Vector3 dir)
{
transform.rotation = Quaternion.Euler(0, 0, Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg - 90);
}728x90
'프로그래밍 > Unity' 카테고리의 다른 글
| Unity 네비메쉬 2D (0) | 2021.01.26 |
|---|---|
| KinematicObject 계열의 캐릭터 주의점 (0) | 2021.01.25 |
| LayerMask.NameToLayer / Equals 성능/포퍼먼스 (0) | 2021.01.14 |
| Spine Render Separator (0) | 2021.01.08 |
| JobQueue (0) | 2020.12.27 |
댓글