백지부터 시작하는 이세계 코딩 생활
Rotation, Rotate 본문
월드 공간에서 회전을 처리할 때 사용한다.
사용은 transform.Rotate 이며 Y 축을 기준으로 회전시킨다. ( 3가지 방법이 존재한다 )
Rotation 과 Rotate 가 있다.
유니티는 내부적으로 회전을 쿼터니언(Quaternion)으로 저장합니다.
오브젝트를 회전하려는 경우에는 Transform.Rotate를 사용합니다.
오일러 각도(euler angles)로 회전을 설정하려는 경우에 Transform.eulerAngles를 사용합니다.
※ Transform 과 transform 의 차이 (Ref. mingyu0403.tistory.com/22 )
Transform - 게임 오브젝트가 가지는 기본 컴포넌트이다. 위치, 회전, 크기 정보를 담고 있다.
transform - 오브젝트에 할당된 Transform 컴포넌트이다. GetComponent<Transform>() 과 같다.
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour {
void Example() {
transform.rotation = Quaternion.identity;
}
}
private void Rotation(Vector3 _lookDirection)
{
if (_lookDirection != Vector3.zero)
rb.MoveRotation(Quaternion.LookRotation(_lookDirection));
}
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour {
public float smooth = 2.0F;
public float tiltAngle = 30.0F;
void Update() {
float tiltAroundZ = Input.GetAxis("Horizontal") * tiltAngle;
float tiltAroundX = Input.GetAxis("Vertical") * tiltAngle;
Quaternion target = Quaternion.Euler(tiltAroundX, 0, tiltAroundZ);
transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * smooth);
}
}
Ref.
Ref.
Ref.
docs.unity3d.com/kr/530/ScriptReference/Transform-rotation.html
'백지부터 시작하는 이세계 유니티 생활 since 2020' 카테고리의 다른 글
MovePosition (0) | 2020.11.18 |
---|---|
Quaternion, LookRotation, Normalize (0) | 2020.11.18 |
GetComponentInChildren, GetComponentsInChildren (0) | 2020.11.18 |
Awake -- Script 및 함수들 작동 우선순위 (0) | 2020.11.18 |
Coroutine, IEnumerator, yield return (0) | 2020.11.17 |
Comments