“2D Lihat Unity” Kode Jawaban

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);
Outstanding Ocelot

Persatuan melihat 2D

Vector3 dir = target.position - transform.position;
 float angle = Mathf.Atan2(dir.y,dir.x) * Mathf.Rad2Deg;
 transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
Courageous Cowfish

2D Lihat Unity

//this code will point the object to the mouse
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);
Daragard

2D Lihat 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);
    }
}
Sam Kessler

Jawaban yang mirip dengan “2D Lihat Unity”

Pertanyaan yang mirip dengan “2D Lihat Unity”

Lebih banyak jawaban terkait untuk “2D Lihat Unity” di C#

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya