修改后2龙不自动面向玩家问题

This commit is contained in:
ZYT
2025-12-02 18:32:02 +08:00
parent 403b0473fd
commit 44a7c39d79
6 changed files with 53 additions and 30 deletions

View File

@@ -45,9 +45,20 @@ public class BlackDragon : Enemy
public override void Update()
{
base.Update();
if (isAlive)
//if (isAlive)
//{
// UpdateLookRotation();
//}
if (isAlive && GameManager.Ins._player != null && state == EnemyState.Atk)
{
UpdateLookRotation();
Vector3 direction = GameManager.Ins._player.transform.position - transform.position;
direction.y = 0;
if (direction != Vector3.zero)
{
// 直接设置旋转,不使用插值
transform.rotation = Quaternion.LookRotation(direction);
}
}
}
@@ -108,15 +119,15 @@ public class BlackDragon : Enemy
});
}
public void UpdateLookRotation()
{
if (GameManager.Ins._player != null&& state== EnemyState.Atk)
{
Vector3 lookDir = GameManager.Ins._player.transform.position - transform.position;
lookDir.y = 0;
transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(lookDir), Time.deltaTime * 5);
}
}
//public void UpdateLookRotation()
//{
// if (GameManager.Ins._player != null&& state== EnemyState.Atk)
// {
// Vector3 lookDir = GameManager.Ins._player.transform.position - transform.position;
// lookDir.y = 0;
// transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(lookDir), Time.deltaTime * 5);
// }
//}
/// <summary>
/// 普通攻击一次

View File

@@ -44,9 +44,21 @@ public class LightingDragon : Enemy
public override void Update()
{
base.Update();
if (isAlive)
//if (isAlive)
//{
// UpdateLookRotation();
//}
//最简单直接的转向
if (isAlive && GameManager.Ins._player != null && state == EnemyState.Atk)
{
UpdateLookRotation();
Vector3 direction = GameManager.Ins._player.transform.position - transform.position;
direction.y = 0;
if (direction != Vector3.zero)
{
// 直接设置旋转,不使用插值
transform.rotation = Quaternion.LookRotation(direction);
}
}
}
@@ -105,15 +117,15 @@ public class LightingDragon : Enemy
});
}
public void UpdateLookRotation()
{
if (GameManager.Ins._player != null&& state== EnemyState.Atk)
{
Vector3 lookDir = GameManager.Ins._player.transform.position - transform.position;
lookDir.y = 0;
transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(lookDir), Time.deltaTime * 5);
}
}
//public void UpdateLookRotation()
//{
// if (GameManager.Ins._player != null && state == EnemyState.Atk)
// {
// Vector3 lookDir = GameManager.Ins._player.transform.position - transform.position;
// lookDir.y = 0;
// transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(lookDir), Time.deltaTime * 20);
// }
//}
/// <summary>
/// 普通攻击一次