How to tell what direction I'm moving in (F/B/L/R)

I’m still rather new to Unreal and game development in general; so please, bare with me.

Basically I’m trying to find out what direction my player is moving, I need that info to dictate what type of action my player should take, for example playing different attack animations depending on the direction player im moving, or deciding what directional animation to play when my character rolls.

I’m going to assume this is all wrong, but this is what I have in terms of my combat blendspace if this helps get an idea what I’m trying to achieve here.

Basic logic I assume would be **bIsAttacking && Direction InRange **

When my player enters the combat blend space I have locked the rotation yaw so the player is always facing the camera direction.

My current way of getting the direction I think is sound (as it’s working for my 2D BS), only problem is it isn’t being set back to 0 when I’m not moving, even with a branch to set direction back to 0 when speed is equal or less than #

This is my first attempt and making a Anim Graph and from the looks of others seen in the past, I could be doing it wrong as well.

Cheers,

Put all that logic into single blueprint function (or macro) inside animation blueprint, then store its result in variable. Animation graph should read that variable, this reduces redundant code in all those decision arrows.
I usually put such code in macros, each macro sets some variable, that anim graph reads.

Sorry, a lot of those branches are just me trying to debug whats going on, and would you still suggest I put this all into a function if this sequence of code is only being used once?

I’ve solved this for the most part, when I’m ready I’ll post an answer for references sake, cheers.

No i suggest you put all complicated logic into macro or function, then you save result of that logic into some variable.
And in anim graph you only read variable and compare if it is in state that allows anim transition or not.

For eg instead of checking if direction is between -180 and 0 (go left) or 0 and 180 (go right), inside anim graph.
You make one function (or macro) that checks direction and sets enum variable to “go left” , “go right” etc. Then in anim graph you just check that variable.
This way if you decide that go left or right should start from +/- 10, you modify only one function, not every arrow decision cod.

This is just hiding code isn’t it? I thought the purpose of Macros/Functions was reusability, something might of been lost in translation (My knowledge is extremely shallow, as you could probably tell).

Would you still recommend storing my move direction into a Enum if I’m doing it this way, my combat system is only based around 5 types of attacks depending on move direction, no plans to extend this in the future.
I mean like, my transition condition isn’t that complicated

Yes I would recommend storing it in variable anyway. You may need bit more complicated condition later on, for eg. move when not jumping and not blocking etc. With one function you pack all logic there.

Ahhh I see now, I’ll get onto it, cheers :slight_smile: