# How to get back to normal speed after accelerating?

Hi! I have simple problem with speed changing. I want to increase velocity instantly after pushing and holding space bar and then when release key I want to get back to normal speed. Here is my code:

``````public class PlayerController : MonoBehaviour
{

public GameObject focalPoint;
private Rigidbody rb;
public float force;
ForceMode fm;
float playerInput;

void Start()
{
rb = GetComponent<Rigidbody>();
}

void Update()
{
playerInput = Input.GetAxis("Vertical");

IncreaseSpeedDuringHoldingKey();

print((int)rb.velocity.magnitude);// info about actual speed of GameObject
}

private void FixedUpdate()
{
rb.AddForce(playerInput * focalPoint.transform.forward * force * Time.deltaTime, fm);
}

void IncreaseSpeedDuringHoldingKey()
{
if (Input.GetKeyDown(KeyCode.Space))
{
fm = ForceMode.VelocityChange;
force = 30f;
}

else if (Input.GetKeyUp(KeyCode.Space))
{
rb.velocity = transform.forward;
fm = ForceMode.Force;
force = 300F;
}
}

}
``````

As you can see I’ve tried with changing the velocity to `rb.velocity = transform.forward` but I’m dissatisfied with this solution because it stops my GameObject completely (rb.velocity.magnitude equals then to 0). What I want to do is to come back to normal speed instantly as if the rapid acceleration never happened (i.e. getting the speed from `rb.AddForce(playerInput * focalPoint.transform.forward * force * Time.deltaTime, fm);`).

Hey,
maybe you could safe the speed before boosting in a variable.
And after the boost is done, you set the velocity to the saved value?

Thanks for your answer! I must say before I asked this question I spent a few hours to solve this problem and nothing worked. Mostly because I couldn’t set the rb.velocity to boost (or slow down) into desirable direction. By that I mean when I added into my code this: `rb.velocity = transform.forward * 30;` my GameObject after pressing space bar moved into weird directions. But just moment ago I noticed that my mistake was in using `transform.forward` instead of `focalPoint.transform.forward` as is in the AddForce method. So I consider this problem as solved.