일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- PYTHON
- getItem
- Unity
- 독립변수
- 연습
- Quaternion
- 도트
- 자주 사용하는 Quaternion 함수
- 코딩
- 탑다운
- className
- javascript
- intervals
- 픽셀
- 웹스크래핑
- 회전
- 도린이
- classList
- 2D
- Lerp
- click
- Event
- 종속변수
- euler
- vsCode
- jQuery
- addEventListener
- setItem
- topdown
- wsl
Archives
- Today
- Total
쫑가 과정
타겟 방향 바라보기 함수 / Quaternion.LookRotation 본문
1. Quaternion.LookRotation
https://docs.unity3d.com/kr/530/ScriptReference/Quaternion.LookRotation.html
Unity - 스크립팅 API: Quaternion.LookRotation
계산된 쿼터니언을 반환합니다. If used to orient a Transform, the Z axis will be aligned with forward/ and the Y axis with upwards if these vectors are orthogonal. Logs an error if the forward direction is zero.
docs.unity3d.com
public static Quaternion LookRotation(Vector3 forward, Vector3 upwards = Vector3.up);
// foward = 정면방향, upward = 위쪽방향을 지정
지정된 앞(forward)과 위(upwards) 방향(directions)으로 회전(rotation)을 만든다.
@ forward방향은 바라보고 있는 (정면)방향 / upward방향은 위쪽 방향.
설명 : Z축은 정방향과 정렬되고, X축은 정방향과 위쪽 사이의 외적과 정렬되고, Y축은 Z와 X 사이의 외적과 정렬
예시) 타겟 방향으로 정면 회전
using UnityEngine;
public class PlayerRotate : MonoBehaviour
{
public Transform target;
void Update()
{
Vector3 relativePos = target.position - transform.position;
Quaternion rotation = Quaternion.LookRotation(relativePos);
transform.rotation = rotation;
}
}
'Unity > 이론' 카테고리의 다른 글
축방향을 원하는 축방향으로 회전하기 / Quaternion.FromToRotation (0) | 2022.01.16 |
---|---|
두 각(Quaternion) 사이를 부드럽게 이어준다 / Quaternion.Slerp (0) | 2022.01.14 |
(Euler) 각을 (Quaternion) 값으로 바꾸기 / Quaternion.Euler (0) | 2022.01.13 |
두 회전 사이의 각 구하기 / Quaternion.Angle (0) | 2022.01.12 |
벡터 연산 이해하기 (0) | 2022.01.07 |
유니티3D 회전 이해 (0) | 2022.01.06 |
객체 지향 프로그래밍의 캡슐화 (0) | 2021.12.28 |
객체 지향 프로그래밍의 상속과 다형성 (0) | 2021.12.28 |
Comments