Unity에서 행성 자전 구현하기
이번에는 자전을 구현해보겠습니다.
자전은 공전과 비슷하게 회전하는 함수를 쓰면됩니다.
[C#] 엔셀라두스 자전 Script
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | using UnityEngine; public class Rotation: MonoBehaviour { public float speed = 10.0f; //회전속도 private void Update() { Orbit_Rotation(); } void Orbit_Rotation() { transform.Rotate(Vector3.down * speed * Time.deltaTime); //transform.Rotate(Vector3 EularAngle) } } |
자전에서는 transform.Rotate함수를 씁니다. RotateAround함수와 달리 자기 자신을 회전시키는 함수입니다.
오일러각도를 이용하는데 오일러각도에 대한 글을 다음에 포스팅하겠습니다.
저번편에서 소개했듯이 Vector3.down (0.0f, -1.0f, 0.0f) 단위백터를 씁니다.
(이번에도 반시계 방향으로 회전합니다. Vector3.Up을 쓰면 시계방향으로 회전합니다.)
Speed : 회전속도 값을 입력
자 위 사진처럼 적용되면 끝입니다.
댓글