Should I use another Mathf??
How would you “smoothly” trigger an oscillation of a variable to start at zero upon entering a trigger, then continue to oscillate [Mathf.Sin(Time.time)*x] until trigger exit, then smoothly return to zero, all at a definable rate?
===>video example
This is what I have so far but doesn't seem to work right , I'm a newbie:
var minimumTwirl = 0;
var maximumTwirl = 12;
private var originalAngle: float = 0;
private var tTwirlIn: float = 1.0;
private var tTwirlOut: float = 1.0;
private var duration: float;
private var trip = false;
function Start(){
var Twirl: TwirlEffect = Camera.main.GetComponent(TwirlEffect);
Twirl.angle = 0;
}
function Update (){
var Twirl: TwirlEffect = Camera.main.GetComponent(TwirlEffect);
var current = Twirl.angle;
if (tTwirlIn < 1.0 && trip == true) { // attempting to smooth if value other than zero
tTwirlIn += Time.deltaTime/duration;
Twirl.angle = Mathf.Lerp(current, minimumTwirl, tTwirlIn);
}
if (trip == true && tTwirlIn > 1){ //start oscillation of value
Twirl.angle = Mathf.Sin(Time.time)*15;
}
if (tTwirlOut < 1.0 && trip == false) { //this works surprisingly well!??
tTwirlOut += Time.deltaTime/duration;
Twirl.angle = Mathf.Lerp(current, minimumTwirl, tTwirlOut);
}