need help with a boost effect

i want to make a boost effect when i press a desired key (in my case left alt)…The thing is I want to do it i nthe same script how would i do it based on these lines of code

if ((groundtrigger.triggered==0)&&(Input.GetButton("Fire1"))&&(speed<800)) speed+=Time.deltaTime*240;
		if ((groundtrigger.triggered==0)&&(Input.GetButton("Fire2"))&&(speed>600)) speed-=Time.deltaTime*240;
		if ((groundtrigger.triggered==0)&&(Input.GetButtonDown("Boost"))&&(speed<800)) transform.Translate(0,0,speed*Time.deltaTime*10);

please tell me if you require more code (for reference)

what i want to do is make the object boost and then it slows down smoothly

can you help me?

Well, you need different variables, like currentSpeedand speed and interpolate it, and always only update speed variable.

if ((groundtrigger.triggered==0)&&(Input.GetButton("Fire1"))&&(speed<800)) speed+=Time.deltaTime*240;
if ((groundtrigger.triggered==0)&&(Input.GetButton("Fire2"))&&(speed>600)) speed-=Time.deltaTime*240;

currentSpeed = Mathf.Lerp(currentSpeed, speed, Time.time * smoothSpeed),
if ((groundtrigger.triggered==0)&&(Input.GetButtonDown("Boost"))&&(speed<800)) transform.Translate(0,0,currentSpeed*Time.deltaTime*10);

This will smooth both, acceleration as well as deceleration…

okay great…i found the solution…

i added this line of code

	if ((groundtrigger.triggered==0)&&(Input.GetButton("Boost"))&&(speed<800)) transform.Translate(0,0,speed/200);

this allows me too boost…all i have to wrry about is smoothing it out…thx all :slight_smile: