- Home /
Value updating only once per second (FIXED, had nothing to do with updates)
Hello, i have this function that is called inside Fixedupdate. (FallAccelleration and FramesPerSecond variables are already set and do not change)
private void Gravity()
{
if (!isGrounded){
falltime++;
DEBUG = 0.5f * FallAccelleration * Mathf.Pow((falltime / FramesPerSecond), 2) ;
transform.position += Vector3.down * DEBUG;
Debug.Log("Spid" + DEBUG);
Debug.Log(falltime);
}
}
For some reason, as i noticed in the debug log, the DEBUG variable is updated only once per second, even though the falltime variable is correctly updated every "fixed" frame. Am i missing something?
I modified the project to have FixedUpdate run at 60/61 FPS instead of the usual 50, if that matters; falltime changes value every frame, but DEBUG only once every 60/61.
Answer by Namey5 · Sep 10, 2020 at 10:10 AM
Are you sure that the debug statements aren't being collapsed? If 'falltime' and 'FramesPerSecond' are both integers, then chances are the division is being counted as integer division and so the value will only update every time 'falltime' is a multiple of 'FramesPerSecond', and if the values are the same and the console is set to collapse then it will skip duplicate debug statements.
You were totally right! Thanks for finding the problem. I changed FramesPerSecond to float and now everithing works fine. Thanks again