Im trying to make my camera speed up gradually till a maximum speed of 2.5f from 0.1f. How would I go round doing this?
thanks in advance/
using UnityEngine;
using System.Collections;
public class CameraMovement : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
transform.Translate(Vector2.down * 0.16f);
if (transform.position.y == 4)
{
transform.Translate(-Vector2.down * 0.16f);
}
if (transform.position.y == -4)
{
transform.Translate(Vector2.down * 0.16f);
}
}
}
That’s a strange script. So if you start from higher than 4, it will go down to 4 and get stuck there, but if you start from lower than 4, it will keep going down, moving twice as fast for 1 frame when at -4? Unless the camera is upside-down or something. I’m not going to touch that part since I am not really sure what you’re trying to do with it. Also, since you’re using Update, is there a reason you’re not using Time.deltaTime to move the camera?
Either way, to answer your question, you could do something like this to speed the camera up:
public class CameraMovement : MonoBehaviour {
float speed = 0.1f;
float speedIncrement = 1.1f; //how fast it increments. tweak this number around to make it slower or faster
void Update () {
if (speed<2.5f) speed*=speedIncrement;
if (speed>2.5f) speed = 2.5f;
transform.Translate(Vector2.down * speed);
}
}