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.

hello! I’m having the same problem with my game! I can’t create an 8-way system like the example you showed. Can’t you share an image of the event system or share the game template? please! I would really appreciate it. thanks.

Check my post below for a screenshot of the state machine events to make this kind of movement :slight_smile:

hi! your character’s movement moves like in the example ( )

Can you share some more details please? I can’t find any more detailed tutorial on the subject of the 8 directions. I wanted to make a movement system like Stardew Valley! thanks

Hey! Yes it moves like that.

Here i made you a better one using a state machine, hope it helps you.

Again, Rogue is the player.

EDIT: Changed a couple things, now it should work the way you want it :slight_smile:

For the actual moving part, its just the Top-down movement behavior, that part is easy, it was the animations that was the tough part :smiley:

I don’t know how to thank you other than a big thank you! it worked 100%. This was exactly what I was looking for! Move in 8 directions without stopping the animations or freezing with multiple buttons pressed! it simply worked! I’ve been trying to resolve this issue for 3 days! The only thing I changed was the name of the animations for my character and the Flip Horizontally!
If you don’t mind, I would like to make a tutorial video and share it with the rest of the world, giving credit to you of course. Thank you one more time!!!

Your welcome! Im glad i could help :smiley:

You dont need my permission to make a video about it :slight_smile: If you want to make it, go ahead! Share the knowledge! Ill be making one too soon.

Just be warned, the programming isnt 100% polished yet, i only realised it last night when i was falling asleep. Theres still one more thing i want to add to it, ill work it out later then make a guide post about it on the General section, ill link it here when its done :smiley:

1 Like

Heres the guide for the complete thing :slight_smile:

This will teach you how to properly do top down animations :slight_smile:

1 Like