自动调整飞机的方向,飞向目标
(相对运动 方向问题)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Myjet : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
//Debug.Log("y轴向量:" + transform.up);
//Debug.Log("x轴向量:" + transform.right);
//Debug.Log("y轴向量:"+transform.forward);
Vector3 face = this.transform.up;
GameObject target = GameObject.Find("飞机2");
Vector3 direction = target.transform.position - this.transform.position;
//得到方向向量
//求旋转夹角
float angle = Vector3.SignedAngle(face, direction, Vector3.forward);
this.transform.Rotate(0, 0, angle);//旋转
}
// Update is called once per frame
void Update()
{
float step = 1.2f * Time.deltaTime;
//沿着机头指向的y方向移动
transform.Translate(0, step, 0, Space.Self);
}
}