# How to make a smooth 2D ski movement?

Hey, I’m trying to make a 2d ski movement to be realistic and feel good. I tried several methods, but I don’t know how to get him to move like that. Watch this video to better understand what I mean.

My code so far:

``````void Update()
{
if (Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Stationary || touch.phase == TouchPhase.Moved)
{
Vector2 touchPos = Camera.main.ScreenToWorldPoint(touch.position);
transform.position = Vector3.MoveTowards(transform.position, touchPos, moveSpeed * Time.deltaTime);
}
}
}
``````

### Please give me some advice or a suggestion on what to try, it will help me a lot.

Thank you

Try this:

• Whenever you touch, you calculate the target angle / rotation of the character and store it in a float field. You can use `Mathf.Atan2` for that.
• In Update, use `Mathf.SmoothDampAngle` to smoothly rotate the character towards the stored target angle.
• Move the character forward. You can use `transform.forward` to calculate the direction. If you are doing a 2D game, `transform.right` or other vector might be more suitable for your setup. Don’t use MoveTowards, because you are moving in a direction, not towards a point. Multiply the direction by speed and deltaTime and add that to your position.
• Optionally, you can have a variable speed. Consider using Mathf.SmoothDamp or at least Mathf.MoveTowards to change the speed gradually over time towards your target speed.

Know that calculating complex motion in Update might give you framerate-dependent result, even if you multiply stuff correctly by deltaTime. My pro tip is to do the gameplay sensitive calculations in FixedUpdate, and optionally do some smoothing interpolation in Update - that way, your character will not experience weird glitches like teleporting over an obstacle or reaching otherwise impossible states when the framerate drops / stutters for some reason.

### Update:

the angle is calculated correctly depending on the touch position and I made a movement, but the player moves faster diagonally than straight. How could I make the player move constantly at the same speed? @Pangamini

My Code so far:

``````void Update()
{
if (Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Stationary || touch.phase == TouchPhase.Moved)
{
Vector3 touchPos = Camera.main.ScreenToWorldPoint(new Vector3(touch.position.x, touch.position.y, 10));
Vector3 direction = touchPos - ski.transform.position;
float angleSki = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg - 90;
ski.transform.eulerAngles = Vector3.forward * angleSki;

transform.Translate(moveSpeed * Time.deltaTime * new Vector3(direction.x, -transform.up.y, 0));
}
}
}
``````