I currently have the camera orbiting behind the player, and I have the Y value reset if the player is not using the joystick to aim. I want to delay the reset so that the camera stays where the player aims for a couple seconds before returning behind the character. More specifically how do I make a variable reduce or gain in value over time?
im not sure what you mean, but does this help?
var TimeRate = 2.0; // To Seconds
private var trp = 0.0;
var lala: 0.0;
function Update () {
if (Time.time > rtp) {
rty = Time.time + TimeRate;
// Do the action!!
// For example ...
lala = lala -(lala/2); // Or Something :P
}
}
There’s a good example of this kind of behaviour in the Unity Third Person Controller script. You’d be looking for this part specifically:
lockCameraTimer += Time.deltaTime;
if (isMoving != wasMoving)
lockCameraTimer = 0.0;
isMoving is the position this frame, wasMoving is the position from last frame. In other words, this lockCameraTimer value will accrue while not changing position, and be reset to zero when you do. Simply use this to hook up your ‘snap behind’ function to run when your camera timer exceeds a given value.