- Home /
Yield function goes slow sometimes/differently?
im scripting thecnical animation that can be change for a couple of different things...exemple this is a majic casting from the ground...
var Time:float=0.01;
var Scaling:float=0.1;
var Scaling:float=0.1;
function Cast(){
for(var i=0; i<Multiplie;i++){
transform.localScale.y+=Scaling;
transform.localPosition.y+=Pos;
yield WaitForSeconds(Time*Time.deltaTime);
}
if(Back)
{
yield WaitForSeconds(BackTime);
for(var iy=0; iy<Multiplie;iy++)
{
transform.localScale.y-=Scaling;
transform.localPosition.y-=Pos;
yield WaitForSeconds(Time*Time.deltaTime);
}
}
}
the things is that im changing the vars depend of the majic that is casted...and i have a lot...so in my first computer yield run faster than my other one, when i play it on lower graphics and resolution it runing more faster again...when i have a lot of particles(particle emitter mostly)it runing slower but, when i use a mathf.lerp for some animation or even a simple rotation in the update or late update funtion...no matter what happen it runing at the same times and if i have a million of particle exemple...it will do the same but just lagging and skipping some frame around but the yield keep runing out slowly? i cant realy transfert my other animation in the update cuz i cant hold it and its so complicated....is there a way of fixing this?
It makes absolutely no sense to multiply the value you pass to WaitForSeconds with Time.deltaTime. It will wait the given amout of seconds. It isn't frame based, it's already time based. But of course like Owen mentioned you can't wait a shorter time than one frame. So if you game runs at 60 fps the shortest time possible is 1/60 of a second == 0.01666 seconds.
i tried both!!!!with and without and its make no difference!!
@hotozi @Bunny83 is correct. I don't think it makes much sense to be using the Time.deltaTime in your WaitForSeconds function. That would lead to inconsistent amount of time to wait. What you're doing would somewhat look like this.
WaitForSeconds(0.000001);
WaitForSeconds(0.000103);
WaitForSeconds(0.000011);
WaitForSeconds(0.000296);
etc, etc..
If you need to change the length of time to wait that's no problem, but I certainly wouldn't do it with Time.deltaTime.
Answer by Owen-Reynolds · Apr 21, 2013 at 03:14 AM
Yield fires on the next frame after the time has past, so can't count small numbers. Exs: yielding 0.00001, waits one frame. Yielding 0.0001 tens times in a row will skip 10 frames.
If you have to do delicate timing, maybe pick the final time and yield frames until then:
while(Time.time<doneTime) {
do my stuff based on Time.deltaTime
yield return null; // wait one frame
}
snap to final value
i get it...but not that munch sorry...can u give me an exemple with my script?
Answer by Eric5h5 · Apr 21, 2013 at 03:30 AM
If you use "yield WaitForSeconds (Time.deltaTime)" then naturally a faster computer will wait for less time than a slower one, since less time has passed since the last frame. Only use absolute time values in WaitForSeconds, never anything multiplied by deltaTime. WaitForSeconds is already inherently framerate-independent; using Time.deltaTime makes it framerate-dependent.
oh ya sorry...forgot to tell u that i used both... wasnt using time.delta time and it were doing the same?
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Coud public variables with same names cause problems? 2 Answers
Yield And Return 2 Answers
Compiling error: [0x00000] in :0 0 Answers