프로젝트/건즈앤 레이첼스
[프로젝트] 오브젝트 주위를 도는 오브젝트 (Rotate Arround)
Bueong_E
2023. 3. 1. 00:06
반응형
SMALL
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float speed = 2f;
public GameObject buddy;
public float orbitSpeed = 100;
Vector3 offset;
public void Init()
{
this.offset = this.buddy.transform.position- this.transform.position ;
}
void Update()
{
this.buddy.transform.position = this.transform.position + this.offset;
this.buddy.transform.RotateAround(this.transform.position, Vector3.forward, this.orbitSpeed * Time.deltaTime);
this.offset = this.buddy.transform.position - this.transform.position;
}
}
캐릭터의 주위를 돌며 공격을 보조하는 버디 시스템을 프로젝트에 추가할 예정이었다.
그래서 사용한 메서드는 transform.RotateAround() 메서드
그렇지만 문제가 있었는데 해당 메서드를 그대로 사용하면 플레이어의 지정된 위치를 쫒게되기 때문에 문제가 생겼다 (다른말로는 궤도가 일그러졌다)
이걸 방지하기 위해 플레이어와 버디의 거리를 지정해주고 지정된 거리만큼을 플레이어의 실시간 포지션에 더해 버디의 와 플레이어의 거리를 지정해주었다.
그리고 버디가 돌기 시작하면 거리를 유지시켜주는 것으로 해당 문제를 해결.
반응형
LIST