Need help with my animation code

im remaking the shovel knight movement in wick editor and the jump animation never stops and it wont let me use the downthrust that I coded (if you get rid of the jump animation code at the top of the players update code then the downthrust works). could I get a bit of help? platformer engine 2.0.09-13-2022_22-37-29.wick

If both yv and xv (Y & X velocities) are zero, then that means that the player isn’t moving right/ left and isn’t in the air. Using this, you can know to stop the jumping animation from playing.

To do that, add this at the top of the update script inside of the clip named player:

if(this.yv+this.xv===0&&s.currentFrameNumber>2)
s.gotoAndStop(1); // you can change this part

Let me know if this works!

How to do that

For the downthrust, I’m guessing you want the player to be in midair, and when they click a type of attacking key, they fall down faster with it. Frame 3 of the character clip (“s”) right?

I’ll use the down arrow key as an example.

Here’s what I’d add to the update script of the player clip to do that:

if(this.yv!==0 && isKeyJustPressed('down'))
s.gotoAndStop(3);
if(s.currentFrameNumber===3){
this.yv = Math.max(this.yv,0.1); // If player is still moving up, now they are falling down
}

I’d also look for the line that has the code for the jump in the update script of the player, you can ctrl + f “upkey” to find it quicker. When you do, this is the line you’re looking for:

if(isKeyDown(this.upKey) && this.yv === this.g) {

Along with the conditions inside this “if” statement, you should make sure that the player isn’t using the “downthrust” attack (this is to prevent a bug that could happen). You can do that by adding an “s.currentFrameNumber!==3” to this “if” statement.

Next, you want to find the line where you switch to the jumping frame for falling down.
I found this by finding the number of the frame in the “s” clip (it was frame 7), and going inside of the update script of the player, and used ctrl+f to find “gotoAndStop(7)”

These are the lines of code you should find:

if (this.og === true) {
    if (this.yv > 0) {
        s.gotoAndStop(7)
    }
    if (this.yv < 0) {
        s.gotoAndStop(6)
    }
}

Now, inside of the “if” statement, “if (this.yv > 0),” you want to make sure that the player isn’t on frame 3. Similar to what we did before, add “s.currentFrameNumber!==3” to that “if” statement.

Next, if you want to disable the right/ left movements in while the player is using “downthrust,” then go inside of player’s update script and use ctrl+f again to find the line with right & left movements. Search something like “rightkey,” and you should find these lines:

if(isKeyDown(this.rightKey)) {
    if(this.xv < this.xvm) {
        // accelerate
        s.width = 160
        s.gotoAndStop(5)
        this.xv += this.acc
    } else {
        // stop accelerating at a point
        this.xv = this.xvm
    }
} else if(isKeyDown(this.leftKey)) {
    if(this.xv > -this.xvm) {
        s.width = -160
        s.gotoAndStop(5)
        this.xv -= this.acc
    } else {
        this.xv = -this.xvm
    }
} 

Add something like “if(s.currentFrameNumber!==3)” at the beginning, so that it looks like this:

if(s.currentFrameNumber!==3)
if(isKeyDown(this.rightKey)) {
    if(this.xv < this.xvm) {
        // accelerate
        s.width = 160
        s.gotoAndStop(5)
        this.xv += this.acc
    } else {
        // stop accelerating at a point
        this.xv = this.xvm
    }
} else if(isKeyDown(this.leftKey)) {
    if(this.xv > -this.xvm) {
        s.width = -160
        s.gotoAndStop(5)
        this.xv -= this.acc
    } else {
        this.xv = -this.xvm
    }
} 

Next, you’d probably notice that the player’s yv is never really 0 when it’s falling down, it stops at 0.1, because of the line that we added, “this.yv = Math.max(this.yv,0.1);”
This is a good thing. Now you know that when the player lands and only after using this move, that the yv is equal to 0.1

If you want to make the player to do damage after landing from this move,or add a special landing animation, this will make it easier to do so.

Go back to these lines that we added in the beginning:

if(this.yv!==0 && isKeyJustPressed('down'))
s.gotoAndStop(3);
if(s.currentFrameNumber===3){
this.yv = Math.max(this.yv,0.1); // If player is still moving up, now they are falling down
}

And change it so that “this.yv = Math.max(this.yv,0.1);” is only run if the yv is not “0.1” when rounded, or “else,” then add code so that the player can do damage or play a landing animation or something.

Note: In the “How to do that” above, I accidentally wrote a “4” instead of a “3” and only noticed after getting so many errors, so if you see any suspicious “4” 's that I might’ve forgotten to replace, let me know. I also noticed this just now, but you’d also need to set the player’s “xv” to zero when the “s” clip’s current frame is 3 to avoid a bug.


Here’s a file example in case you run into any other trouble:
platformer engine 2.0.09-14-2022_9-38-02.wick (201.2 KB)
(I recommend walking through what I wrote above first before downloading the file)

Let me know if this isn’t what you meant, or if anything doesn’t work or make sense.

thanks
I don’t really want the left right movement to stop when downthrusting bu I fixed that myself but it does the walking animation when doing the downthrust and moving. I also coded a breakable block but it starts the jump animation when it bounches you up which I don’t want. platformer engine 2.0.09-14-2022_12-30-09.wick

So you don’t want the jump animation to start, right? I made it so that it stays on the downthrust animation. Let me know if this is what you meant.
platformer engine 2.0.09-14-2022_19-28-14.wick (201.5 KB)

I also fixed that in the file in this post (I think)

thanks, but now I run into the problem that I cannot make the normal attack that’s on frame 4 of the s object work.

Oh yes, I didn’t notice that
Here’s a quick fix:
platformer engine 2.0.09-15-2022_11-43-12.wick (201.5 KB)

thanks,…

1 Like

I just realized that I need some help with the jump because I want the jump to go up 4 1/2 blocks up every time you jump like in shovel knight but in this it does a higher jump the more you hold the button, which I don’t want. shovel knight movement9-15-2022_11-46-44.wick

and now the normal z attack animation glitches when I use it while moving. I also don’t want to be able to move while using z shovel knight movement9-15-2022_12-26-42.wick

I also realized that the blocks started glitching and being basically nothing on the left side

srry for the late reply

Update script of player, line 115, delete the part of the line highlighted in this image:


That way, if you hold the jumping button, the jump won’t increase.
However, it will be a very small jump…

To adjust the height of the jump, go to the default script of the player and find lines 33-38
These lines are technically the settings for the jump, they’re explained in the comments there

To adjust the jump, you’ll have to play around with everything here.
“this.jumpDec” is how much the jump will be decreased. The smaller it is, the more that will be decreased from the player’s jump. It’s like a percentage, at 1 (or 100%), the jump will not decrease at all, anything above might make a never ending jump based on your other variables. At 0 (or 0%) there will be no jump.
“this.g” is also the gravity force, and “this.yvm” is the y-velocity limit.
I recommend setting “this.yvm” to exactly 20, and setting “this.jumpDec” to 1, to get the player to jump up to around 4.5 blocks.

Find line 50 in the update script of the player


Now, all you have to do is add a new line between lines 49 and 50 that says
“if(s.currentFrameNumber!==4)”
Like this:

If you play the project with this, you’ll probably notice that if you use the “z” move while moving, the full animation will play without glitching like before.

Inside the update script of the player, add these two lines of code anywhere to fix that:

if(s.currentFrameNumber===4)
this.xv=0;

I don’t know if this is what you meant, but I realized that while the player is walking into the blocks from the left side the blocks are destroyed upon contact.

If that’s something you don’t want to happen, go inside of the breakable blocks. Take a look at the update script, the last couple lines:

Since Baron’s engine is “pixel perfect,” when the player is moving right and into the platforms, it looks like it’s being blocked by the platform, but 2D wise, it’s not really touching, so the hits function isn’t being run… however, when the player is moving left and hit’s the wall, it’s touching the block, so the “hits” function returns true for “this.hits(player),” which starts the timer and the cool destruction animation for the breakable block.

If you delete those lines or turn them into a comment, then test the game, you’ll notice that while moving left… the player is literally moving into the block… try it.


(If you did delete those lines or turn them into a comment, undo that)

It should be no surprise that the hit’s function was run when it’s moving this much into the block…
There’s a problem with collision.

So let’s take a look inside of the “block funcs” layer, click the only frame there, and go inside of its default script.

The function that starts on line 153 looks like where we need to look to fix this.

Oh… I think I just found the bug…
This function uses the width of the player, and inside of the player, when moving left, you can see that you set the width to a negative number.

So change line 155 in the image above from

var widthDist = (object.width + player.width)/2

to

var widthDist = (object.width + Math.abs(player.width))/2

And now it should be fixed (at least from my side)

If that doesn’t work, go inside of the player clip’s update script, use ctrl+f to find the line, “this.width = -67,” and change it to “this.width = 67”


Also, if you’ve adjusted the jump, you’d probably wanna adjust how high the player jumps up when they break the breakable blocks. That should be in line 164. Change it to something around -20 for better results.


Let me know if this works for you or not.
Here’s a file in case anything doesn’t work (the file might be a bit more messy since I experimented with a bit of other stuff).
shovel knight movement.wick (210.5 KB)

the only way that the collision works is if the player object doesn’t turn around but I want it to turn around

In that case, inside of the breakable blocks code, add conditions to make sure that the block doesn’t break when the player moves from the right side.

To make it easier to change the code for all the breakable blocks, I moved it inside of the breakable block’s function


So the code is there for now, if you want it back inside of the breakable blocks, just replace “object” with “this” and “target” with “player,” then copy paste it.
shovel knight movement.wick (210.5 KB)