2017-06-18 54 views
0

我正在施放一些咒語,並將其設置爲LookAt。問題是LookAt正在將我的法術動畫設置爲不在遊戲對象中。我從中獲得的位置的對象具有比例(3,3,3),網格渲染器,球面碰撞器和剛體。 (其他碰撞體在子對象上)。下面是我使用的鑄造法術代碼:transform.LookAt正在關閉遊戲對象

public void castSpell(GameObject caster, Transform otherTransform, float duration) 
{ 
    if(animationEnabled) 
    { 
     foreach(var a in animator) 
     { 
      foreach(var b in a.bools) 
      { 
       a.animator.SetBool(b.parameterName, b.parameterValue); 
      } 
      foreach(var i in a.ints) 
      { 
       a.animator.SetInteger(i.parameterName, i.parameterValue); 
      } 
      foreach(var f in a.floats) 
      { 
       a.animator.SetFloat(f.parameterName, f.parameterValue); 
      } 
     } 
    } 

    GameObject Temporary_Spell_Handler; 
    Temporary_Spell_Handler = Instantiate(_Spell, Spell_Emitter.transform.position, Spell_Emitter.transform.rotation) as GameObject; 

    ParticleSystemRenderer pr = Temporary_Spell_Handler.GetComponent<ParticleSystemRenderer>(); 
    float dist = Vector3.Distance(caster.transform.position, otherTransform.position); 

    //Add Spell Script to the casted spell so it handes damage and everything about spells. 
    Spell tempSpell = Temporary_Spell_Handler.GetComponent<Spell>(); 
    tempSpell.caster = caster; 

    if(b_lenghtScale) 
    { 
     pr.lengthScale = -lenghtScale; 
    } 

    if(lookAtEnemy) 
    { 
     Temporary_Spell_Handler.transform.LookAt(otherTransform); 
    } 

    Destroy(Temporary_Spell_Handler, duration); 
} 

,這裏是像它看起來的樣子:

enter image description here

我發現這個問題。我的ball被縮放到(3,3,3),所以它上升並且對象的支點停留下來。那我該如何克服這個問題呢? enter image description here

+0

我不確定是什麼問題。你能添加一個你期望*發生的截圖嗎? – Draco18s

+0

你看到閃電正在地面,而不是球(談到雷電中心)。所以我想以某種方式改變角度。 –

+1

這將完全取決於你的對象的設置和性質。如果閃電的圖形與遊戲對象的軸線不對齊,則圖形需要修復。如果預製平面與軸不對齊,那麼需要固定。如果預製軸沒有指向你希望它指向的位置,那麼這就是完全不同的問題。*我無法從你發佈的圖片中知道它是哪一個。 – Draco18s

回答

1

我創建了空gameobject並將其設爲我的ball的父級。然後,我將gameobjects的位置(現在是樞軸)設置在我不會(在球的中心y = 5的位置),然後在球上我做了相反的操作(y = -5)。

然後到遊戲對象我創建爲支點我添加標籤pivotChange,然後在我的castSpell腳本我在lookAtEnemy部分做出這種變化:

if(lookAtEnemy) 
    { 
     if(other.transform.parent != null && other.transform.parent.gameObject.tag == "pivotChange") 
     { 
      Temporary_Spell_Handler.transform.LookAt(other.transform.parent.gameObject.transform); 
     } 
     else 
     { 
      Temporary_Spell_Handler.transform.LookAt(other.transform); 
     } 
    } 

而且它的工作好。

+0

很高興你能解決它。 :)基本上問題在於你的預製件的支點位置在一個地方(在那個黃色磁盤所在的地方),爲了使它正確瞄準,你需要有一個子對象(或新的父對象)在預期的位置有其樞軸。這是我對這個問題的第一次猜測,但我無法確定,但我確實傳授了一些關於如何調試的知識。 :) – Draco18s

+0

非常感謝:) –