using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public class QuaternionTest : MonoBehaviour
{
public Transform player;
public float Distance = 5.0f; // Player로부터의 거리
public float Speed = 50.0f; // 도는 속도
void Update()
{
OrbitPlayer();
}
void OrbitPlayer()
{
if (player == null) return;
// Player 주위를 도는 오브젝트의 위치 계산
float x = Mathf.Cos(Time.time * Speed) * Distance;
float z = Mathf.Sin(Time.time * Speed) * Distance;
transform.position = new Vector3(x, 0, z) + player.position;
//Player를 바라봄
transform.LookAt(player);
}
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Enemy"))
{
Debug.Log("Hit!");
}
}
private void OnDrawGizmos()
{
if (player == null) return;
Gizmos.color = Color.white;
float theta = 0;
float x = Distance * Mathf.Cos(theta);
float z = Distance * Mathf.Sin(theta);
Vector3 prevPos = player.position + new Vector3(x, 0, z);
for (theta = 0.1f; theta < Mathf.PI * 2; theta += 0.1f)
{
x = Distance * Mathf.Cos(theta);
z = Distance * Mathf.Sin(theta);
Vector3 newPos = player.position + new Vector3(x, 0, z);
Gizmos.DrawLine(prevPos, newPos);
prevPos = newPos;
}
Gizmos.DrawLine(prevPos, player.position + new Vector3(Distance * Mathf.Cos(0), 0, Distance * Mathf.Sin(0)));
}
}
QuaternionTest.cs
반응형
'산대특 > 게임 플랫폼 응용 프로그래밍' 카테고리의 다른 글
Animation Curve를 이용해서 점프 구현해보기 (0) | 2024.03.05 |
---|---|
배경 스크롤링 구현하기 (0) | 2024.03.05 |
유니티 공식 오브젝트 풀링 API로 총알(Bullet) 프리팹 관리하기 (0) | 2024.03.04 |
Bullet 발사 시에 오브젝트 풀링으로 Bullet 관리하기 (0) | 2024.03.04 |
A* 알고리즘 구현해보기 (3) - 구해진 경로를 따라 오브젝트 이동 시켜보기 (0) | 2024.03.04 |