I am creating a fighting game where there are startup frames and lag. The method of programming I have previously used is basing changes in game state off of delta time. How would I go about creating a game where the changes in the game are determined by the amount of frames that have gone by?
Update is running every frame
void Update () {
frameCounter ++;
if (frameCounter > amountOfFrames) {
//do something
}
}
I think, this is bad idea to use the frames as time interval.
Keep in mind that framerates are variable. If you’re trying to use this for fighting game mechanics the way I think you are then you’re probably going to want to use a fixed framerate:
You can also avoid targeting a specific frame rate by performing your calculations in the FixedUpdate() method. You can then adjust the amount of Updates happening per second in Edit > Settings > Time > Fixed Timestep.
FixedUpdate is run 50 times per second by default regardless of framerate and would be an ideal solution for what you are trying to achieve.
Please be aware changing the fixed update time “could” play havoc with your physics calculations.
This is a viable solution, although from my knowledge of fighting games (which is admittedly limited) he probably wants to have his entire simulation in lockstep with his framerate so that animation frames directly sync 1:1 with behavior.
If I’m wrong, please correct me on this.
From my understanding, most fighting games run with animation times and behavior times based on frames. For example, a punch might have 1 frame of startup, 2 active frames and then 1 lag frame. The hitboxes would correspond with the frames displayed.