Fair warning, what I did was a deviation from what was done in the course. Instead of freezing one animation for jumping, I decided to make a couple of jump animations myself for my character.
That said, I don’t have any idea why this is happening. The attached videos below show the problem.
Here’s my code for handling jumps (including jump input):
//jump check
if(IsKeyPressed(KEY_SPACE) && !isInAir)
{
velocity += JUMP_VELOCITY;
int random = GetRandomValue(0, 3);
if(random < 3)
{
currentLunaAnimation = lunaJump1;
selectedJumpAnim = lunaJump1AnimData;
}
else
{
currentLunaAnimation = lunaJump2;
selectedJumpAnim = lunaJump2AnimData;
}
currentRec = selectedJumpAnim.rec;
jumpAnimPlaying = true;
}
Then skipping code for handling velocity
//update luna animation frame
//Jump Animation
if(jumpAnimPlaying)
{
selectedJumpAnim.runningTime += DELTA_TIME;
if(selectedJumpAnim.runningTime >= selectedJumpAnim.updateTime)
{
if(velocity < 0)
{
if(selectedJumpAnim.frame < 3)
{
selectedJumpAnim.frame++;
}
}
else
{
if(!landing)
{
if(selectedJumpAnim.frame < 6)
{
selectedJumpAnim.frame++;
}
else if(selectedJumpAnim.frame == 6)
{
lunaAnimData.runningTime = 0;
landing = true;
}
}
else
{
lunaAnimData.frame = 7;
selectedJumpAnim.frame = 0;
}
}
selectedJumpAnim.runningTime = 0;
}
currentRec.x = selectedJumpAnim.frame * selectedJumpAnim.rec.width;
}
//Skate animation
else
{
lunaAnimData.runningTime += DELTA_TIME;
currentLunaAnimation = luna;
if(lunaAnimData.runningTime >= lunaAnimData.updateTime)
{
currentRec = lunaAnimData.rec;
lunaAnimData.frame++;
if(lunaAnimData.frame > 17)
{
lunaAnimData.frame = 0;
}
lunaAnimData.runningTime = 0;
currentRec.x = lunaAnimData.frame * lunaAnimData.rec.width;
}
}
Here’s a video showing the problem: https://www.youtube.com/watch?v=N96_6y1qoB0