private void FixedUpdate()
{
//刚体导航
Vector3 direction = player.position - transform.position; //确定目标方向
Vector3 deltavelocity = direction - rigid.velocity;
rigid.AddForce(deltavelocity, ForceMode.Force);
float rotationAngle = AngleAroundAxis(transform.forward, direction, Vector3.up);
rigid.angularVelocity = Vector3.up * rotationAngle;
}
static float AngleAroundAxis(Vector3 dirA,Vector3 dirB,Vector3 axis)
{
dirA = dirA - Vector3.Project(dirA, axis);
dirB = dirB - Vector3.Project(dirB, axis);
float angle = Vector3.Angle(dirA, dirB);
return angle * (Vector3.Dot(axis, Vector3.Cross(dirA, dirB)) < 0 ? -1 : 1);
}