I suppose you're talking about
17:26 in the video.
boagz57
Is my understand of what 't' is even correct?
t is the amount of time elapsed from some point in time (e.g. when an animation has started), not from the game start.
boagz57
Why are animations updated with t instead of with dt?
t is the amount of time since the animation started. That amount is still calculated using dt (each frame t is incremented by dt).
boagz57
What I don't understand is how 't' is used in practice for animations?
When you create an animation in an animation package you have precise curves (or a key each frame) between 0 and the length of the animation. So you can call a function with a time parameter and get the exact result of the animation. This also work if you execute a function that can give the result independently of the previous state (the only parameter is the time). This is the f(t) case. It will always give you the same result. Note that this result can be used in further computation instead of using it directly (for example the root motion in Unity 3D that uses the displacement of the root node to move the actual object).
When you move a character, you can't use a function f(t) because depending of where the character is in the world, f(t) would need to return a different position. In other words, the current state f(t0) of the character is necessary to compute the next state f(t1). This is the f(t0) + f'(t1) * dt case. f'(t1) * dt is the amount of change from f(t0) to f(t1).
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 | /* In this example
* - pos.x is updated using physics;
* - pos.y is updated using animation.
*/
Vec2 pos = { };
r32 anination_t = 0.0f;
b32 jump = false;
while ( running ) {
b32 move = keyPressed( "move" );
if ( !jump && keyPressed( "jump" ) ) {
jump = true;
animation_t = 0.0f;
}
if ( move ) {
pos.x = pos.x + speed * dt; /* f(t0) + f'(t1) * dt */
}
if ( jump ) {
pos.y = animate( "jump", animation_t ); /* f(t) */
animation_t += dt;
if ( animation_t > animation_length( "jump" ) ) {
jump = false;
}
}
}
|