我正在創建一個基于 Skyrim 和 For Honor 戰斗的多人第一人稱中世紀格斗游戲,具有 3 種不同的姿勢。在其中,你可以從3個架式進行攻擊,如果對手沒有保持相同的架式,他就會進行攻擊,否則他會招架并且攻擊者會快速眩暈。當劍的 Hitbox 擊中玩家自己的 hitbox 時,問題就開始了,從而導致了不必要的結果。
這就是為什么我想知道有沒有辦法讓玩家的劍無視與玩家本身的碰撞,讓他無法攻擊自己。
我也試過把方法:Physics.IgnoreCollision(collider, selfCollider); 在 OnTriggerEnter() 函式、Start() 和 Update() 內部,沒有任何解決方案有效。
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Enemy" || other.gameObject.tag == "Player")
{
//instant enemy combat
CombatManager enemy = other.gameObject.GetComponentInChildren<CombatManager>();
Debug.Log(enemy.currentStance);
//If enemy stance is not the same of the attacker
if(enemy.currentStance != this.currentStance)
{
//enemy is damaged
//Get enemy LifeManager and subtract its health
enemy.GetComponentInParent<LifeManager>().currentHealth -= swordDamage;
}
else
{
anim.SetTrigger("Parried");
}
}
uj5u.com熱心網友回復:
嘗試:
if(other.transform.root != transform.root)
{
// NOT self collision
}
這基本上檢查兩個物件是否屬于同一層次結構。換句話說,如果它們具有相同的最頂層 GameObject 或根。
顯然,我對你的玩家頭像是如何操縱的做了一些假設。也許您需要調整此解決方案以適應您的層次結構。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/435353.html
