Need Help With Jump animation

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Biphe
Prole
Posts: 13
Joined: Sun Jun 17, 2012 1:38 am

Need Help With Jump animation

Post 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.
Attachments
jump.love
(85.93 KiB) Downloaded 146 times
User avatar
bdjnk
Citizen
Posts: 81
Joined: Wed Jul 03, 2013 11:44 pm

Re: Need Help With Jump animation

Post 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.
Biphe
Prole
Posts: 13
Joined: Sun Jun 17, 2012 1:38 am

Re: Need Help With Jump animation

Post by Biphe »

Hmm... What is a finite state machine?
User avatar
MadByte
Party member
Posts: 533
Joined: Fri May 03, 2013 6:42 pm
Location: Braunschweig, Germany

Re: Need Help With Jump animation

Post 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
User avatar
bdjnk
Citizen
Posts: 81
Joined: Wed Jul 03, 2013 11:44 pm

Re: Need Help With Jump animation

Post 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.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 1 guest