2017-11-30 14 views
0

私がやっていることは、プレイヤーにライオンと敵と他の動物がいるということです。parentとset localpositionsとgameobjectsから特定のローカルロケーションへのローテーション

私が望むのは、プレイヤーが死ぬときに敵を掴んで首に入れて、彼と一緒に連れて行くことです。

すべての敵の動物は、首の地位を持っていますが、それらはすべて異なっています。すべての動物は異なる位置を持っているので

Enemy1.SetParent(DragMouth.transform); 
    Enemy1.gameObject.transform.position = Enemy1.GetComponentInChildren<Neck>().transform.TransformPoint(0,0,0); 
    Enemy1.localRotation = Quaternion.identity; 

これはちょっと動作しますが、それが良い動作しません。

は何私が持っていることは、これがあります。

"Dragmouth"の位置に敵の首を設定する正しい方法は何でしょうか?

私はユニティbtwを使用しています。

+0

だから、あなたのDragMouth(ライオン) gameobjectは一度にすべての敵の首をつかむでしょうか? – Mazhar

+0

一度に1つの敵からだけではなく、プレイヤーが敵を殺した後、彼を口につかんで別の位置に移動するような選択肢があります。 –

+0

hmmm .....何もない? –

答えて

0

自分の位置から首の位置までのオフセットを知っている動物にスクリプトを追加できます。その後、敵がターゲットをつかむようになると、オフセットをベース位置に差し引くだけで正しい位置に保ちます。だから、 のようなもの(例のコードは、回転のみの調整なしで動作しますNOTE、あなたはそれが回転:)で動作させるためにいくつかのより多くの計算を行う必要があるでしょう):

public class Lion : Monobehaviour 
{ 
    public Vector3 offsetToMouth 
    { 
     get { 
      return mouthObject.localPosition;   
     } 
    } 

    //Make a child object that is on the mouth position 
    //Reference to this object through unity inspector 
    public Transform mouthObject; 

    //The target that is currently in lions mouth 
    private Target currentTarget; 


    void Update() 
    { 
     var mouthPosition = transform.position + offsetToMouth; 
     var newPosition = mouthPosition - currentTarget.offsetToNeck; 
     currentTarget.gameObject.transform.position = newPosition; 
    } 
} 

public class Target : Monobehaviour 
{ 
    public Vector3 offsetToNeck 
    { 
     get { 
      return neckObject.localPosition;    
     } 
    } 

    //Make a child object that is on the neck position 
    //Reference to this object through unity inspector 
    public Transform neckObject; 
} 
関連する問題