This commit is contained in:
杨号敬 2024-11-27 20:21:19 +08:00
parent f9bded8800
commit 05fa2ede36

View File

@ -58,7 +58,7 @@ public class WingmanController : MonoBehaviour
// 让僚机跟随主机
FollowPlayer();
target = FindClosestEnemy().transform;
// 让僚机开火
@ -83,19 +83,17 @@ public class WingmanController : MonoBehaviour
// 僚机发射导弹
private void FireMissile()
{
// 创建导弹并发射
GameObject missile = Instantiate(missilePrefab, missileSpawnPoint.position, missileSpawnPoint.rotation);
target = FindClosestEnemy().transform;
//Todo僚机追踪子弹
if (target != null)
{
// 旋转导弹朝向目标
GameObject missile = Instantiate(missilePrefab, missileSpawnPoint.position, missileSpawnPoint.rotation);
Vector3 direction = target.position - missile.transform.position;
Quaternion targetRotation = Quaternion.LookRotation(direction);
missile.transform.rotation = targetRotation;
float distance = Vector3.Distance(missile.transform.position, target.position);
float moveDuration = Mathf.Clamp(distance / 20f, 0.2f, 0.7f);
// 向目标前进
missile.transform.DOMove(target.position, moveDuration);
}
}