- Home /
InvokeRepeating rate slowing down without indication
Hello! I have this script called WobbleHandler to give certain objects in my game a nice smooth wobble. The script works on a seperate delta time/update rate in order to improve performance. I recently made an addition so that the script would be able to change the delta time if the game's frame rate dropped, since this script is entirely superficial.
The problem is that when the InvokeRepeating is called from within the function itself the update rate is halved! Entirely without any indication (the deltaTime and speed values are the same in the inspector). When the frame rate returned to normal this problem persisted, and the objects appeared to move in slow motion. I fixed this by changing the invoke rate to deltaTime/2 (which worked!), but that only made it clear that this problem was only for some objects. Other objects aren't affected in the same way and thus move at double speed when the invoke rate changes. Have I missed something obvious, or is this pretty wierd? Here's the code:
var deltaTime : float = 1f/30f;
var speed : float = 0.2;
function WobbleUpdate () {
timer += deltaTime / speed;
timer2 += deltaTime / (speed * 1.7);
var toLerp = Mathf.Sin(timer) / 2 + .5f;
var toLerp2 = Mathf.Sin(timer2) /2 + .5f;
//Do Stuff
if(Mathf.Abs( deltaTime - CustomFPS.targetDeltaTime ) > deltaTime/4 ){
CancelInvoke();
deltaTime = CustomFPS.targetDeltaTime;
InvokeRepeating("WobbleUpdate", deltaTime/2, deltaTime/2); //after my initial solution
}
}
function Enable(){
InvokeRepeating("WobbleUpdate", 0, deltaTime);
isEnabled = true;
}