I am trying to rotate my GameObject to be facing in the direction that it is moving. I am not using Rigidbody.Velocity, I am just using transform.position to move the object. Here is my code:
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;
}
}
}
Any suggestions on how to implement rotation? I am completely stumped