Enemy 4Way Animation

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

First let me say, I’m a NEWB. Only have been learning about development for games for about a month now, so, sorry in advance for my lack of knowledge.

Right now, I have a pretty simple 2D RPG Top Down game. My question though is how do I get my enemy to animate in the direction it is moving. I have set up an animation player and animation tree. The enemy already has an Idle, Wander, and Chase state that work in the game. I just can’t seem to get my enemy to animate like the main character, based on the direction it is headed. All I can get it to do is flip_h but stuck in the idle facing down. I feel as if I’m just forgetting a connection in the code, but as I’m still trying to learn code, I’m not to sure what I’ve missed or may of messed up.

Right now, everything works with no errors, the only thing that doesn’t happen is switching between idle and walk animations. The enemy is just stuck on idle down. I thought it’d be as simple as just recreating the player’s movement/animations, but again, I don’t entirely know what I’m doing. Any help, feedback, suggestions, would be greatly appreciated!

Script for the enemy below as well as my Setup

Could I please take a look at your AnimationTree?

SQBX | 2023-01-03 20:51

Sure! I have both set up like this, y at 1.2 and -1.2 while x is at 1 and -1
Idle to walk, with transition being automatic, and the blend line being on the dotted line (forgot what that was called)

snowleopardspaw | 2023-01-04 03:59

Any ideas as to what I might of done or what I could do?

snowleopardspaw | 2023-01-04 21:20

I don’t see anything or anywhere that calls the walk() function.

LeslieS | 2023-01-05 04:32

Is that something I’ll still need? As of now, they move on their own randomly switching between the states of Wander, Idle, and Chase (when the player crosses into their detection zone). Do I need a walk() function in order for the animations to work? I’m sorry I’m really new and got a little ambitious with this project. So I’m not entirely sure what I’m doing, just kind of messing around with it till it works ha.
How would one go about doing this? Any good tutorial links/videos you know about?

I’m trying to make a small game to display my music and sound effects (for my final portfolio project to graduate) as well as display my interest in the graphic art/game development skills that I literally just learned this past month.

snowleopardspaw | 2023-01-05 05:55

In order for the animation tree to switch from idle to walk the function travel() needs to be called.
Those two functions are the only places travel() is called.
I am not exactly sure where you should call it from however. Its hard to say since you have 3 states but none of them are ‘walk’.
Maybe in the update_wander() function add:

if state == WANDER: 
    walk() 
elif state ==  IDLE: 
    idle() 

And change those functions so they no longer take a parameter (delta).

Assuming your animations contain all 4 (or 8) directions Flip.h will have to be removed. You are kind of mixing two ways of animating movement.

You could try going through HeartBeast’s player movement episode again and maybe it will help.

You should post code using the code tag {}. You will find that on the tool bar above the text box. Make sure you have one blank line before the code and one after and look at the preview below the textbox to see if it is formatting correctly.

LeslieS | 2023-01-05 06:28

Thank you for such amazing information.
I was trying to use the code option on here but it kept splitting up everything incorrectly (just my lack of understanding of how it works) so thank you for that tip.
I’ll back track a bit and research what you suggested a little more. Heartbeast was a HUGE help, definitely helped get me started, but I’ve been trying to take what I’ve learned from his channel and move past just copying him line for line. I have been going back to his videos as refreshers though as I find his tutorials to be the most comprehendible for someone of my stature (newb).

snowleopardspaw | 2023-01-05 17:42