Help with 8 direction movement

So I’ve been working on getting 8 direction movement to work without using the top down movement behavior. I wanted something a bit more complex. What I want to happen is say when I press the “w” key the player moves up and plays the “walk up” animation. If I continue to hold down “w” and then press the “d” or “a” key the player moves on a diagonal and continues to play the “walk up” animation. I want the player to continue playing the same animation of the first key that is pressed. The top down movement behavior has 8 possible key combinations. My method would have 12 key combinations, plus 4 for releasing keys and playing an idle animation. I have set it up using variables so that each combination of keys gives a different variable: 1, 2, 3 …16. An animation is played based on the value of the variable. This somewhat works so far. Some combination of keys plays the correct animation, while others the player will turn and play a different animation from what it’s supposed to.

Here is what the events look like right now.

ok but i want to know what is the problem, the animations or the movement?

The events you use aren’t really built for what you want to do with the animation. If you really want to make complex animations, consider creating a finite state machine:
I’d store the player’s max speed in a variable (say 60), then an X and Y axes variable of player input, which can be -1 (left/up) or 1 (right/down) - reset them both every frame, A/D keys affect X axis to -1 or 1, and there will be a final event that actually moves the character based on the max speed variable and the axes input variables.
Then, you can use the condition “player is NOT moving” of Force to set the animation, and put the “set animation” events in a Trigger Once sub events.
If that doesn’t make sense, definitely check out the above link. It’s not top-down but the knowledge will help you very much.

1 Like

Ok, thank you. This looks interested. I’ll look into it.

@reina Yes! I finally got it working! I’m so happy. :smile: The finite state machine makes this work perfectly now. I went ahead and exported and uploaded it to the gdevelop hosting. Here’s the link if you want to see what I was talking about. Move around with WASD. The background is just a place holder. I made the player sprites using Flipnote Studio 3d on my 3DS. :laughing: That’s all I’ve got so far.

1 Like

It’s really good, and I’m glad you managed to understand the tutorial yourself!
As another note, since you’re using pixel art sprites, you’ll want to turn off image smoothing (blur) in project settings and for each image, so when the game is full screen it will not appear blurry.
Here: Top left button, Game Settings, Project Settings, Scale Mode

and here:

Make sure “Smooth the image” is unticked for every single picture in your project so far, and it’ll not blur.
However text will always blur even when you use pixel font later - the fix is still in development, you can take a look around forums for it.

Ah, ok. I thought it looked a little blurry.