- Home /
How do i make my character not "instantly" get to and from max speed?
Hello I have been self scripting the code to my game, "the carpet Rouge" and I have ran into a tiny little detail... Whenever I press the up and down keys my character instantly goes to max speed (20), and when I let go of the key he does the same thing. I want him to slowly build up to the max speed, and then slowly slow down into an idle state! Do not mind the (keycode.space) that is just a booster function for my game
here is the script, HELP!?
#pragma strict
var movespeed : float = 5;
var rotateSpeed : float = 5;
var jumpHeigth : float = 10;
var smoothDamp
function Start ()
{
}
function Update ()
{
if (Input.GetKey(KeyCode.UpArrow))
transform.Translate(Vector3.forward * movespeed * Time.deltaTime);
if (Input.GetKey(KeyCode.DownArrow))
transform.Translate(-Vector3.forward * movespeed * Time.deltaTime);
if (Input.GetKey(KeyCode.RightArrow))
transform.Rotate(Vector3.up, rotateSpeed * Time.deltaTime);
if (Input.GetKey(KeyCode.LeftArrow))
transform.Rotate(Vector3.up, -rotateSpeed * Time.deltaTime);
if (Input.GetKeyDown(KeyCode.Space))
movespeed = movespeed + 15;
if (Input.GetKeyUp(KeyCode.Space))
movespeed = movespeed - 15;
}
Answer by YoungDeveloper · Jul 13, 2014 at 10:03 AM
Yes, because 15 is added when you press the space key and 15 is removed when you release it. What exactly you want to do, add speed like an event when button is pressed and remove it slowly when reach 20, or add it only if player is holding the space?
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
UnityEngine.Input.GetMouseButton(1)) issue 1 Answer
Player slows down unless selected before hitting play in editor 1 Answer
I made a better shader how do i fix[add _Shadow Strength]help???>Sorry that im asking for to much 1 Answer
Variable Question. [Simple] & [JS] 1 Answer