make moving sprite face the direction unity 2d code example
Example 1: unity face direction of movement
transform.rotation = Quaternion.LookRotation(dir);
Example 2: how to move a 2d character in unity
if (moveInput != 0)
{
velocity.x = Mathf.MoveTowards(velocity.x, speed * moveInput, walkAcceleration * Time.deltaTime);
}
else
{
velocity.x = Mathf.MoveTowards(velocity.x, 0, groundDeceleration * Time.deltaTime);
}