Falling animation instead of idle and run animations

I keep getting a problem with “java.lang.ArrayIndexOutOfBoundsException: Coordinate out of bounds!”

Please help!

You give us no context to the error, which makes it really hard to guess at?

Nah that is fine. I just had to restart my PC.

However, I do have a problem with my animations. Whenever my sprite is on the floor, he is doing the idle animation and also doing the falling animation. I have been trying to look at the code and fix it for a long time but I just don’t know what to do.

pic 1 for forum
pic for forum 2

This is my code for my animations. Please tell me if there is anything I can do, since this is from the platformer tutorial website (i mean i literally took the whole movement thing and adjusted it so it worked for me)

You should start a separate thread for this issue. It would also be helpful to post your code in text rather than as screenshots.

Begin code by typing ``` and then again after the code.

Like this
1 Like

Yh sure I will start doing that. Could you just tell me how to thread posts since I’m here the first time so I don’t know much.

Welcome!

I mean you should start a new topic, like this one but specific to the animation issue you are having. This topic is named ’ Defold Game Project Problem’ which isn’t relevant to the question you have posted most recently.

1 Like

Alright, can you tell me what piece of the code you would like to see?

I just assume it is a platformer, but (also for future) you could tell this to us upfront, to know what you are trying to achieve and what is the problem exactly, otherwise, we can’t help :wink: Mind showing us the gif/recording of the problem? And how do you determine self.velocity and self.ground_contact? Do you use some collisions for this or something else? As looks like you have frequently changing values here, thus an effect in animations changing :slight_smile:

Hi, Yes. I am in A-Level Computer Science and I need to make a game for next year. The game I will be making (what I want it to be like anyway) is a sonic prototype. So for now, I am just practising defold since at the beginning it looked quite frightening. Currently, I am on school property so I cannot make recordings just yet but like in a hour or so, I can make recordings and make these much clearer.

To summarise what is going on, I have all my animations ready. I have checked that all of the other ones work (idle, run and jump) beforehand. And as soon as I included the falling animation, it started to mess up my normal methods of movement (idle and run). From what I can understand, the game thinks that my sprite is on the ground for a few seconds, so it displays the idle animation. But from time to time, it will think that (for some reason) I was in the air, so it will make a falling animation. Same thing to when I run.

Please add prints with current values and investigate it:

    if self.velocity.x > 0 then
        print("Idle")
        play_animations(self, idle_idle)
    else
        print("Run")
        play_animations(self, run_run)
    end

and:

if self.velocity.y > 0 then
    print("Jump")
    play_animations(self, jump_jump)
else
    print("Fall")
    play_animations(self, fall_fall)
end

and add some prints at the beginning of update_animation() and at the end, before leaving it.

Only one print between those marks should be visible, so then - investigate where in the code your self.ground_contact is changed, add prints - because it looks like it is changing all over time and not properly detect ground collision - so how do you detect ground collision?

You surely can’t have only sprite - you have a game object with sprite and either a script in which you set position and determine/calculate if such position is a “ground_contact” position or you have raycasts or triggers or kinematic physics component which tells you so - so how do you handled setting self.ground_contact? :wink:

The self.ground_contact was on the tutorial. I had said before that I copied and pasted the whole thing and changed a few bits so it worked for me. I now added the prints but I just got more problems.

  1. There is no running animation anymore
  2. I get an error " player/player.script:66: attempt to call global ‘play_animations’ (a nil value)
    stack traceback:"
  3. When I jump then land, the animation doesn’t go back to idle, but now my character is on the ground doing the jumping animation

The code that I had before this print change works better since I can at least see my player run and land normally. Maybe the velocity.x > 0 is making a big difference?

You need to slow down and look through your code and compare the state it was in when it worked and the state after you added your print() commands.

One of these changes most likely broke the code from the tutorial right? I assume the tutorial did not show this behaviour. Again, check what changes you made and carefully apply them one by one and observe the result. You should be able to pinpoint which change you made that caused the problem in the first place.

Going slowly and methodically through your code will help you become a better programmer and will help you if you decide to pursue a career as a programmer. It may be boring to backtrace like this, but I can assure you that it will help you in the long run!

4 Likes

Screen capture - 4cf5c4146c50be92d5f4790e99cae134 - Gyazo = this is what it normally is. For some reason though the idle and running animations aren’t working properly but at the moment, the player normally stands and normally runs


= i have added in the falling animation and it now for some reason overtakes my idle and running animation