백지부터 시작하는 이세계 코딩 생활

Rotation, Rotate 본문

백지부터 시작하는 이세계 유니티 생활 since 2020

Rotation, Rotate

조아덕 2020. 11. 18. 17:18

월드 공간에서 회전처리할 때 사용한다.
사용은 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.

mingyu0403.tistory.com/22

 

[Unity] Transform (위치, 회전, 크기)

Transform에는 position, rotation, scale로 위치, 회전, 크기를 담고 있다. ※ Unity는 왼손 좌표계를 사용한다. 빨간색 -> x축 (양수 오른쪽, 음수 왼쪽) 초록색 -> y축 (양수 위쪽, 음수 아래쪽) 파란색 -> ..

mingyu0403.tistory.com

Ref.

itmining.tistory.com/48

 

[유니티 트랜스폼] 회전 (Rotate)

이 글은 PC 버전 TISTORY에 최적화 되어있습니다. 서론 3D 게임에서 회전이라는 요소는 굉장히 중요합니다. 앞만 보고 달리는 오버워치 캐릭터를 생각해보면 아찔합니다. 이번에는 마우스의 좌, 우

itmining.tistory.com

 

Ref.

docs.unity3d.com/kr/530/ScriptReference/Transform-rotation.html

 

Unity - 스크립팅 API: Transform.rotation

유니티는 내부적으로 회전을 쿼터니언(Quaternion)으로 저장합니다. 오브젝트를 회전하려는 경우에는 Transform.Rotate를 사용합니다. Transform.Rotate를 사용합니다. 오일러 각도(euler angles)로 회전을 설정

docs.unity3d.com

 

Comments