1

オブジェクトがスポーンされたときに、向きを変えて敵オブジェクトに向かって移動するようにします。すでに移動は機能していますが、敵への回転は機能していないようです。

これが私の現在のコードです:

GameObject newRocket = GameObject.FindGameObjectWithTag("Enemy");
direction = (cil.transform.position - novaStrela.transform.position);
rotationDirection = Quaternion.LookRotation(direction);
newRocket = Instantiate (rocket, transform.position, rotationDirection) as GameObject;
newRocket.rigidbody.AddForce ((target.transform.position - transform.position).normalized * projectileSpeed);

面倒なことは承知しておりますが、お役に立てれば幸いです。今までありがとう

4

1 に答える 1

3

これを試してください:

Vector3 v3Dir = transform.position - _destination.position;
            float angle = Mathf.Atan2(v3Dir.y, v3Dir.x) * Mathf.Rad2Deg;
            transform.eulerAngles = new Vector3(0, 0, angle);

ここで、transform.position はロケット (オブジェクトを見たいもの) の位置で、_destination.position は見たいオブジェクトの位置です。これは 2D ゲームの私のコードなので、いじる必要があるかもしれません。

于 2015-03-16T13:26:13.863 に答える