have to stop player walking first in order to attack. how to reverse process.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By chris33556

The question says it all. i have a player with walking movement and a punch action move. in beat-em up games the when the player requires to punch , the sprite just stops walking and executes the code to attack.

However, in my script i cant punch until i actually stop walking first. can someone advise me on the my script how to do the reverse.i.e the movement stops on pressing the action button . here is the script:


You need to read or watch tutorials about state machines. Otherwise, even if You fix this one, You will encounter massive amount of other problems like this. For example You will notice, that your punch cancels your kick, or that your walking freezes when input is held still.

Inces | 2022-08-17 16:21

I have been having these problems yeah . I’ve had to try 2 different ways to implement a movement and action system and it’s been a pain but I’m still learning everyday. I’ll look into state machines. thanks for the suggestion

chris33556 | 2022-08-17 16:57

:bust_in_silhouette: Reply From: SnapCracklins

Seconding the recommendation on state machines, but I think the problem is in your input vector. You are having the movement reference that vector when it is at zero before you start moving. However, you never reset the vector when your player stops, so the movement is getting the value of that vector. I would also recommend breaking your “idle” and “walk” and “punch” code into separate functions (which is another step towards a proper state machine.) This will also help your code be cleaner and easier to maintain.

Try resetting that input vector where you need to stop moving.

input_vector = Vector3.ZERO


movement = Vector3.ZERO