How do I gradually increase the speed of a configurable joint? When I assigned a value of Vector3(0,0,5) to a conjo rotating about z-axis, value 5 is applied instantly. Is there a way to make the speed goes up gradually to assigned speed?
You can use Vector3.Lerp(). As an example:
private const float Duration = 2f;
private float endTime = -1f;
private Vector3 startValue;
private Vector3 endValue;
public void Update() {
if (Time.time<=endTime) {
float a = (endTime-Time.time)/Duration;
Debug.Log(Vector3.Lerp(startValue,endValue,a));
}
else if (Input.GetKeyDown(KeyCode.E)) {
endTime = Time.time + Duration;
startValue = transform.position;
endValue = startValue + Vector3.right;
}
}