- Home /
Question by
Daniel G · Jul 08, 2013 at 06:31 PM ·
javascriptlerptimescalebending
Smooth the Changes in TimeScale, in TimeBending script
Hello, I made this JavaScript for an effect much like need for speed most wanted, where you could slowdown time to make difficult corners by pressing a key.
Two Questions: 1. Is this hard on an iOS Device (its processor consumption) 2. How do i apply a Lerp or Slerp to the time changes?
Code:
#pragma strict
var bendTimeDown : boolean = false;
var bendTimeUp : boolean = false;
var BendTimeUpCompleted : boolean = false;
var count : float = 0;
function Update(){
BendTimeTrigger ();
BendTimeDown ();
BendTimeUp ();
}
function BendTimeTrigger () {
if (Input.GetKeyDown("t")) {
count++;
}
if (count == 0) {
BendTimeUpCompleted = false;
bendTimeDown = false;
bendTimeUp = false;
}
if (count == 1) {
bendTimeDown = true;
bendTimeUp = false;
BendTimeUpCompleted = false;
}
if (count == 2) {
bendTimeDown = false;
bendTimeUp = true;
}
if (BendTimeUpCompleted == true) {
count = 0;
}
}
function BendTimeDown () {
if (bendTimeUp == false) {
if(bendTimeDown == true){
if (Time.timeScale == 1.0) {
yield WaitForSeconds(.2);
Time.timeScale = 0.8;
Debug.Log (Time.timeScale);
}
if (Time.timeScale == 0.8) {
yield WaitForSeconds(.3);
Time.timeScale = 0.6;
Debug.Log (Time.timeScale);
}
if (Time.timeScale == 0.6) {
yield WaitForSeconds(.4);
Time.timeScale = 0.4;
Debug.Log (Time.timeScale);
}
if (Time.timeScale == 0.4) {
yield WaitForSeconds(.5);
Time.timeScale = 0.2;
Debug.Log (Time.timeScale);
}
}
}
}
function BendTimeUp () {
if (bendTimeDown == false) {
if(bendTimeUp == true){
if (Time.timeScale == 0.2) {
yield WaitForSeconds(.5);
Time.timeScale = 0.4;
Debug.Log (Time.timeScale);
}
if (Time.timeScale == 0.4) {
yield WaitForSeconds(.4);
Time.timeScale = 0.8;
Debug.Log (Time.timeScale);
}
if (Time.timeScale == 0.8) {
yield WaitForSeconds(.3);
Time.timeScale = 1;
BendTimeUpCompleted = true;
Debug.Log (Time.timeScale);
}
}
}
}
Thanks Daniel
Comment