I’m rotating an object which has a number of point lights attached with the object as parent. The lights are blinking with a script. Issue is: When the lights blink on, the rotation speed of the object slows down, any reasons for this beyond simple FPS issue due to adding lights?
Scripts below.
Rotate script:
var rotateSpeed : float = 1.5;
rotateSpeed = rotateSpeed * Time.deltaTime;
function Update () {
transform.Rotate (0,0,rotateSpeed);
}
Your rotation code is frame rate dependent. Adding a light lowers the frame rate (as it is more expensive to render) and therefore also slows down your rotation.
To make your rotation frame rate independent, change your code to:
var rotateSpeed = 1.5;
function Update ()
{
transform.Rotate (0,0,rotateSpeed * Time.deltaTime);
}
Time.deltaTime returns the time since the last frame and as a result varies over time.
As a side node: it is really never a good idea to have lines of code (that don’t start with var) outside of functions in java script. You can never really know when the code will be executed or even if the functions and values you use have a sensible value.