How do I script the player character to dash?

Hello, I’m developing a prototype for my 3D topdown game in C#. I have a capsule as my player character; he can move (although twice as fast when moving diagonally), rotates according to what direction he is moving, and has a camera following him without rotating with him.

Now, I’m trying to get him to ‘dash’–to move a few metres in the direction he’s facing in half a second when the ‘Z’ key is pressed.

So far, I made two floats: - public float dashDistance & public float dashSpeed

Where do I go from here? (I’m very new to programming)

Maybe something like

if ( dashing )
{
transform.postion=Vector3.Lerp(currentPosition, target, dashSpeed*Time.deltaTime);

if ( Vector3.Distance(tranform.postion,target) < 0.1f )
{
dashing=false;
}
}else{
if ( Input.KeyUp(KeyCode.Z) )
{
dashing=true;
target=transform.position*dashDistance;
}

// Regular movement code
}

Code is completely untested… but something like that

Please note: you should Lerp from your initial position, rather than currentPosition, in your loop. Otherwise as you get closer to your final position, you’ll slow to a crawl and unless your framerate dips below 1FPS, you’ll never actually reach your target destination.