unity3d模型运动转向移动简单控制

1.转向
(1)根据目标点
rotation = Quaternion.LookRotation(target - transform.position);
  transform.rotation = rotation;
 //transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * rotatespeed);平滑
(2)根据速度
 Vector3 v = rigidbody.velocity;
 transform.localRotation = Quaternion.AngleAxis(Mathf.Rad2Deg * Mathf.Atan2(v.x, v.z), Vector3.up);
2.朝目标点移动
transform.position = Vector3.MoveTowards(transform.position, target, Time.deltaTime * runspeed);

你可能感兴趣的:(移动,unity3d,控制,转向)