Right, I’ve come upon an interesting issue. Usually, when playing, it takes 2 shots of the laser I created in the game to kill an enemy, however, if I have a window open on my other screen with a video playing, which results in an FPS drop, it now only takes 1 shot.
this is how I substract the health
(where the healthDamage var is an int that never changes)
Now, I’d have thought that including Time.deltaTime would have prevented this- what gives?
Is your laser an instant hit weapon or a damage over time weapon?
If its an instant hit weapon then there is no sense at all to use Time.deltaTime or any other time dependent variable.
If its damage over time I would suggest that you either use FixedUpdate which is guaranteed to be called a fixed ammount of time over a time perioid or use a timed Coroutine.
Also dont use int for the healthDamage variable if its time dependent. On assigning a floating point type to an integer the value will be truncated:
0.999 → 0
thanks Marrrk!!! changing Update() to FixedUpdate() solved the issue!! why isn’t everything FixedUpdate??? (why does Update exist then in the first place)
Update is called every frame, so if you want super smootheness for animations or something like this Update is your friend.
ahh okey, thanks mate I applaud your eruditeness!
FixedUpdate doesn’t have any guarantees like that, and relying on it will cause code to break in low framerate situations. FixedUpdate is for physics only, not timing.
–Eric
This means over a duration of 1 second and a fixedUpdate timeStep of 0.1s FixedUpdate will not be called 10 times? Good to know, thank you.
You should really use Time.deltaTime. From what I remember FixedUpdate called at a comparable rate to Update() is more expensive.
It probably will, but the point is you can’t count on it. You should really just use it for physics and nothing else; there’s no reason to use it for timing when other methods are more reliable.
–Eric
float framerate = 2.0f;
IEnumerator Start ()
{
// do some initialization
while (Application.isPlaying)
{
yield return new WaitForSeconds (1.0f / framerate);
SampleUpdate ();
}
}
void SampleUpdate ()
{
// Do your checks
}