1
\$\begingroup\$

So I am very new to Game Dev, and I am running into a problem that seems like it should have a simple answer. Unfortunately, I have not been able to figure it out.

I am creating a 2d side scroller. I have incorporated a quick and heavy attack the player can execute on the ground, and a set of attacks when the player is jumping. However, when the air attacks animate, the player continues falling to the ground - often landing before the attack animation finishes. I would like to lock the players position in the air until the animation finishes, and then allow the player to fall it is complete. I haven't figured out how to stop and make the player hover in place during the animation. I've searched around for a solution, but haven't been able to find an explanation.

This doesn't seem like a particularly unique concept, and I am hoping somebody has some sort of similar experience. I would be happy to provide any extra information needed. Thank you for any help you can provide.

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

Assuming your player character is a CharacterBody2D, you are in charge of moving it.

For example, you might be adding gravity to the velocity, something like this would suffice:

velocity += gravity * delta 

So temporarly disabling gravity is a matter of setting a flag and checking it before doing the gravity computation. For example, we can declare:

bool _attacking := false 

On your attack code you set:

_attacking = true 

And you might want to connect a method to the finished signal of your animation player, so you can there reset the flag:

_attacking = false 

And then we can check:

if not _attacking: velocity += gravity * delta 

As alternative, you might check which is the current animation of the animation player, and use that to know if the player is attacking.

\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.