I want to advance animation at a strict rate of exactly 1 frame per update. I do not want any skipped frames which I believe unity will do if you just set it to play an animation.
So it would look something like
function Update()
{
gameObject.animation.advanceOneFrame();
}
I want to do this so that attacks have the same consistent frame data.
A punch should have 4 frames of startup and 10 frames of recovery for example, allowing for the player to always have the same things work.
Kick X will always be able to hit after blocking Punch Y, but I think this will not happen properly if frames are skipped.
Sounds like you’re making a fighting game? Well, here’s the good news: Update() will strictly run once per frame, though not necessarily at the exact same timing each frame. On the other hand, the animator will always run based on Time.deltaTime, but should be separate from your actual game logic. If you’re getting skipped animation frames, then that’s a symptom of not running at 60 fps, rather than a problem in and of itself.
What this means is if you’re counting in frames (rather than Time.deltaTime), you can be certain that the frame data of your game will be consistent, though not necessarily the timing of each action. The downside to counting in frames (instead of Time.deltaTime) is that any drop in frame rate will result in attacks dragging on for longer than they should, and if you’re balancing around reaction windows, this can subtly shift expected timings. If you’re going to count in frames, you absolutely must be certain that you are running at a smooth 60 fps (or whatever your target is). If you can do that, then the problem solves itself.
If you insist on having the animation sync up with the reduced frame rate rather than fixing the frame rate problem itself, it’s possible to set the playback time each frame. If you call animator.SetTime(currentDesiredFrameInAnimation / maxFramesInAnimation);
every frame, it will ensure that the playback time of the animation matches whatever frame rate you’re running at. Animator.SetTime() is how I implement hitstop and Super freeze in my own fighting game, so if you’re planning on implementing those or similar features, you’ll probably need to use it anyway.