I need to increase the speed of an object in Unity over time so it kinda moves like if you were on ice, or sliding around. Something like that, here’s the code:
#pragma strict
public var player : GameObject;
static var selectedId : int;
var speed : float = 0;
private var minimum = 0;
private var maximum = 4;
private var tParam : float = 0;
function Update () {
if (Input.GetKey (KeyCode.UpArrow)) {
//speed += Time.deltaTime * 2.5f;
if (tParam < 1)
tParam += Time.deltaTime * 0.9;
speed = Mathf.Lerp(minimum, maximum, tParam);
}
else if (Input.GetKey (KeyCode.DownArrow)) {
//speed += Time.deltaTime * 2.5f;
if (tParam < 1)
tParam += Time.deltaTime * 0.9;
speed = Mathf.Lerp(minimum, -maximum, tParam);
}
/*else {
while (speed > 0)
speed -= Time.deltaTime * .7f;
}*/
transform.Translate (Vector2(0, 1) * Time.deltaTime * speed);
}
It works absolutely fine except for the fact then after the speed reaches it’s maximum, it stops working like it should, removing the actual effect I wanted it to give. I want there to be a maximum speed you can go, but not remove the sliding effect on the object.