1.控制朝向transform.LookAt(target.transform);
2.实现跟随,逐渐靠近
GameObject player;
float MAX_MOVE_DISTANCE=500.0f;
void FixedUpdate()
{
float moveDistance=MAX_MOVE_DISTANCE*Time.deltaTime;
Vector3 source=transform.position;
Vector3 target=player.transform.position;
Vector3 seekVelocity=Seek(source,target,moveDistance);
seekVelocity=UsefulFunctions.ClampMagnitude(seekVelocity,moveDistance);
rigidbody.AddForce(seekVelocity,ForceMode.VelocityChange)
}
Vector3 Seek(Vector3 source,Vector3 target,float moveDistance)
{
Vector3 directionToTarget=Vector3.Normalize(target-source);
Vector3 VelocityToTarget=moveDistance*directionToTarget;
transform.LookAt(player.transform);
return velocityToTarget-rigidbody.velocity; //注意,这里是向量相减
}