【发布时间】:2021-04-05 13:02:44
【问题描述】:
好的,计划很简单。 我的计划是制作一个简单的 AI,记录每个玩家的位置,然后使用这些位置跟随玩家。所以AI总是会落后玩家一些步骤。但是当玩家停止移动时,AI 会与玩家发生碰撞,然后玩家就会死亡。
所以我的问题是当玩家被AI追赶时,它总是在敌方AI能够接触玩家之前跑出位置......
我使用 Queue 来制作职位列表,这是我尝试使用 List 后有人推荐的。 Here's a video showing the problem
public Transform player;
public Transform ghostAI;
public bool recording;
public bool playing;
Queue<Vector2> playerPositions;
public bool playerLeftRadius;
void Start()
{
playerPositions = new Queue<Vector2>();
}
// Update is called once per frame
void Update()
{
if (playerLeftRadius == true)
{
StartGhost();
}
Debug.Log(playerPositions.Count);
}
private void FixedUpdate()
{
if (playing == true)
{
PlayGhost();
}
else
{
Record();
}
}
void Record()
{
recording = true;
playerPositions.Enqueue(player.transform.position);
}
void PlayGhost()
{
ghostAI.transform.position = playerPositions.Dequeue();
}
public void StartGhost()
{
playing = true;
}
public void StopGhost()
{
playing = false;
}
private void OnTriggerExit2D(Collider2D other)
{
Debug.Log("Player leaved the zone");
playerLeftRadius = true;
}
如何改进它以使其能够接触到玩家?
【问题讨论】:
标签: c# arrays unity3d queue position