Page 1 of 1

Need Help With Jump animation

Posted: Mon Dec 23, 2013 7:08 pm
by Biphe
So I have the jump frames added. But every time I press the up arrow key to jump the player won't move up if I am also hold the right arrow key. It shows the jump animation when I press up while standing still. I need help making the player continue the jump animation while moving in either a left or right direction.

The love file is included. and here is some of the code.

Re: Need Help With Jump animation

Posted: Mon Dec 23, 2013 7:38 pm
by bdjnk
Your code contains an animation hierarchy (if, elseif, else) in player.update, with jump below everything but idle. I've "fixed" the problem by moving jump to the top:

Code: Select all

if love.keyboard.isDown('up') then
  playerSprite = playerJump
elseif love.keyboard.isDown('right') ...
As you may surmise, this is not a true solution. What you really want is a finite state machine, which we can talk about if you'd like.

Re: Need Help With Jump animation

Posted: Mon Dec 23, 2013 9:02 pm
by Biphe
Hmm... What is a finite state machine?

Re: Need Help With Jump animation

Posted: Mon Dec 23, 2013 9:19 pm
by MadByte
:ultrahappy: Hi Biphe,

to archive this you could add a extra variable which indicates whether the player is in air or not .
jump.love
Here is your .love file modified with the change. I just added the isJumping variable and also had to split up the if elseif loop because it would cause problems with what yout want to archive. ( note I just fixed what you suggested. The jump itself still have to be corrected. )

edit: here is your .love with the jump fixed. If you want figure out how to do it on your own, please don't open it !
jumpFixed.love

Re: Need Help With Jump animation

Posted: Tue Dec 24, 2013 12:16 am
by bdjnk
Biphe wrote:Hmm... What is a finite state machine?
At a theoretical level, a finite state machine is simply a set of states and the acceptable transitions between those states.

Using your character as an example, you have the following states: standing, crouching, walking, jumping. When in a jumping state, I should be unable to transition to any other state (except perhaps crouching). When crouching I should be unable to jump or walk (unless we're talking about crabwalking), but standing is okay.

Basically your current state restricts the allowable transitions, while circumstances determines which state to transition to. So, for example, I press jump but I'm currently crouched. Nothing happens, because state forbids it.

This is often used in AI as well. If I get too close, an enemy could enter a defensive state, engaging cautiously. When within striking distance they could enter an attack state. There's no way for an attack state to go anywhere but a defensive state. In defensive mode danger is determined and attack decision are made.

Usually finite state machines are described by enums and case switch statements, both of which are not so simple in lua. Still, it's often worth it.

Sorry if this explanation isn't so clear. I tried.