I have a camera in my scene that moves to the side like in a side scrolling game. I have the camera gradually pick up speed over the course of 94 seconds, then after those 94 seconds, i want the camera speed to suddenly increase over a short period of time.However, no matter what i do, i cant seem to increase the value of the camera speed past the “maxSpeed” in the first Mathf.SmoothStep. See anything wrong with my code?
EDIT: The Speed now changes with the changed code, but it changes instantly no matter how long BoostAccelerationTime is, how do i make it change over time?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraMovement : MonoBehaviour {
public float CameraSpeed;
public float maxSpeed = 9f;
public float accelerationTime = 94;
private float minSpeed;
private float time;
private float minSpeed2;
public float Boost = 10f;
public float BoostAccelerationTime;
void Start () {
minSpeed = CameraSpeed;
time = 0;
minSpeed2 = 9;
}
// Update is called once per frame
void Update () {
time += Time.deltaTime;
if (time < accelerationTime)
{
CameraSpeed = Mathf.SmoothStep(minSpeed, maxSpeed, time / accelerationTime);
}
if (time >= accelerationTime + 1)
{
CameraSpeed=Mathf.SmoothStep(minSpeed2,minSpeed2 + Boost,time/BoostAccelerationTime);
}
transform.position += transform.right * CameraSpeed * Time.deltaTime;
}
}