I need to slow down several objects according to their speed: the faster the speed, the longer it will take to slow down.
I tried with a Lerp function but I don’t manage to make it work…
Mathf.Lerp() doesnt work the way you think. The third argument is effectively the percent along the lerp you want. so you’ll want to have something like a counter variable or store the time and compare to the new time. My suggestion would be something like:
Have this somewhere else in the class(not in a function)
There are many different ways of doing this depending on your goal. Here is one way. In a new scene, create a game object, put it to the left edge of the Game window, and add this script.
#pragma strict
var velocity = Vector3(6.0, 0.0, 0.0);
var slowFactor = .5; // needs be between 0 and 1
function Update() {
transform.Translate(velocity * Time.deltaTime);
velocity = velocity * (1.0 - (slowFactor * Time.deltaTime));
if (velocity.magnitude < 0.1)
velocity = Vector3.zero;
}