我正在尝试将我的游戏对象旋转到它正在移动的方向。我没有使用 Rigidbody.Velocity,我只是使用 transform.position 来移动对象。这是我的代码:
public GameObject player;
void Update ()
{
Vector3 _origPos = new Vector3(player.transform.position.x,player.transform.position.y, player.transform.position.z);
if (Input.touchCount > 0)
{
// The screen has been touched so store the touch
Touch touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Stationary || touch.phase == TouchPhase.Moved) {
// If the finger is on the screen, move the object smoothly to the touch position
Vector3 touchPosition = Camera.main.ScreenToWorldPoint(new Vector3(touch.position.x, touch.position.y, 10));
transform.position = Vector3.Lerp(transform.position, touchPosition, Time.deltaTime);
//transform.LookAt(new Vector3(touchPosition.x,touchPosition.y,0), Vector3.up);
Vector3 moveDirection = gameObject.transform.position - _origPos;
}
}
}
关于如何实施轮换的任何建议?我完全被难住了