fix:调整目标朝向问题

This commit is contained in:
bzx
2025-08-29 18:41:53 +08:00
parent 40eacaebc5
commit a56b727086
10 changed files with 133 additions and 83 deletions

View File

@@ -251,7 +251,7 @@ public class Enemy : Agent
{
if (target != null)
{
transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(target.transform.position - transform.position), Time.deltaTime * 10f);
transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(target.transform.position.ReflectVectorXOZ() - transform.position), Time.deltaTime * 10f);
}
}
@@ -305,7 +305,7 @@ public class Enemy : Agent
if(isServer)
GameManager.Ins.DeleteEnemy(id,transform);
}, 1f);
AnimatorComponent.SetBool("dead", true);
AnimatorComponent.SetTrigger("dead");
GameManager.Ins.PlaySound3DRPC(dieSound,transform,true);
}
}
@@ -368,24 +368,9 @@ public class Enemy : Agent
// 在 server 上播放死亡并通知客户端
Vector3 hitPoint = transform.position;
if (info is Vector3) hitPoint = (Vector3)info;
Debug.Log("得分:"+info);
if(info is int i && i != -1)
GameManager.Ins.AddScore(i.ToString(), GameManager.Ins.EnemyInfos[type].Score);
RpcPlayDeath(hitPoint);
// 播放死亡音效(在客户端通过 RpcPlayDeath 会触发本地 PlaySound
// Server 端额外处理:生成爆炸/掉落/计分等
//PlayServerDeathEffects();
// 最终 server 可决定是否销毁网络对象
if (/*你想直接销毁*/ false)
{
NetworkServer.Destroy(gameObject);
}
else
{
// 保持对象存在,直到 server 另外决定销毁
}
}
[ClientRpc]
@@ -516,7 +501,7 @@ public class Enemy : Agent
public Transform attackPoint; // 攻击检测点
private float attackRange = 4f; // 攻击半径
public float attackAngle = 45f; // 扇形角度
private float attackAngle = 90f; // 扇形角度
public LayerMask playerLayer; // 玩家所在的层
/// <summary>
@@ -531,10 +516,8 @@ public class Enemy : Agent
// 判断是否在前方45度范围内
Vector3 dirToTarget = (hit.transform.position - attackPoint.position).normalized;
float angle = Vector3.Angle(attackPoint.forward, dirToTarget);
if (angle <= attackAngle * 0.5f) // 扇形角度一半
if (angle > attackAngle ) // 扇形角度一半
{
Debug.LogError(hit.gameObject.name);
Player player = hit.GetComponent<Player>();
if (player != null)
{

View File

@@ -100,6 +100,8 @@ public class GameManager : NetworkBehaviour
public Dictionary<TowerType, List<Tower>> TowerList2 = new Dictionary<TowerType, List<Tower>>();
public Dictionary<string, SettleInfo> SettleInfos = new Dictionary<string, SettleInfo>();
[SyncVar]
public bool isStart;
/// <summary>
/// 波次自增
@@ -111,7 +113,7 @@ public class GameManager : NetworkBehaviour
[SyncVar]
public long vistEnd = 0;
// 总游玩时长
private int vistAllTime = (int)(60 * 1f);
private int vistAllTime = (int)(60 * 10f);
[SyncVar]
public string settleData = "";
@@ -465,6 +467,7 @@ public class GameManager : NetworkBehaviour
EnemyList.Remove(id);
if (id == 2)
{
Debug.LogError("创建爆炸");
CreateExplosion(pos,id);
}
curRoundEnemyCount--;

View File

@@ -81,6 +81,7 @@ public class HUDPanel : MonoBehaviour
EventDispatcher.AddEventListener<int>("UserGun", UserGun);
EventDispatcher.AddEventListener<int>("WinRound", ShowWinRound);
EventDispatcher.AddEventListener<int>("ChangeGunIcon", ChangeGunIcon);
LessTimeText.text = "10:00";
}
public void HpChange(float currentHp, float maxHp)