Quaternion.LookRotation

|

두 점 사이의 각도를 계산할때 사용하는 API 함수

static Quaternion LookRotation(Vector3 forward, Vector3 upwards = Vector3.up);


forward는 바라보는 물체 

upwards는 기본값이 Vector3.up으로 정의되있음.






Quaternion.LookRotation

static Quaternion LookRotation(Vector3 forwardVector3 upwards = Vector3.up);
Parameters

forwardThe direction to look in.
upwardsThe vector that defines in which direction up is.
Description

Creates a rotation with the specified forward and upwards directions.

Returns the computed quaternion. If used to orient a Transform, the Z axis will be aligned with forward and the Y axis withupwards if these vectors are orthogonal. Logs an error if the forward direction is zero.
using UnityEngine;
using System.Collections;

public class Example : MonoBehaviour {
    public Transform target;
    void Update() {
        Vector3 relativePos = target.position - transform.position;
        Quaternion rotation = Quaternion.LookRotation(relativePos);
        transform.rotation = rotation;
    }
}
See Also: SetLookRotation.


Trackback 0 And Comment 0