so i want to make a time freezer in a script which enemies has it to move up and down, and i want the script to smoothly (smoothly really) move slower and slower and then stop, same as unfreezing time.
private Vector3 pos1;
private Vector3 pos2;
public Vector3 posDiff = new Vector3(0f, 0f, 20f);
public float speed = 1.0f;
public bool Freezeable = true;
public GameObject PistonObject;
void Start()
{
pos1 = transform.position;
pos2 = transform.position + posDiff;
}
bool Freeze = false;
void Update()
{
if (Freeze == false)
{
transform.position = Vector3.Lerp(pos1, pos2, Mathf.PingPong(Time.time * speed, 1.0f));
}
if (Freeze == false && Input.GetKeyDown(KeyCode.E) && Freezeable == true)
{
speed -= Time.deltaTime;
Freeze = true;
}
else if (Freeze == true && Input.GetKeyDown(KeyCode.E) && Freezeable == true)
{
speed += Time.deltaTime;
Freeze = false;
}
that is what i’ve done so far.
the problem is, -= and += doesn’t smoothly change value.
the freezeable bool is just to make some enemies don’t be affected (immune enemies.)