I need help getting the direction the character is facing for a dash mechanic.

im making a top down 2d game and trying to add a dash but i can figure out how to get the characters forward direction so i can add a dash, as i have disabled the rotation so the sprite wouldn’t rotate and that’s broken the usual method of, get actor rotation → get forward vector, i would really appreciate the help .

You can use the Get Last Input Vector node, expose it’s components (either by right clicking on it’s Return Value pin and splitting it or by using the Break Vector node), check if it’s Y (or X, depends on your orientation) component is 1 or -1, and set a bool type variable which we can name “IsFacingRight” to True when it’s 1 and False when it’s -1 (or vice versa, like I said, it depends)

However, we can make it more straightforward, by setting a bool type variable according to your Input Action value. That way you don’t need to check where the player is facing constantly. I just wanned to give that answer as well.

Hope this helps! :innocent:

thank you for this but this doesn’t really work in top down 2d game where there’s more than one direction to move in.

thank you for helping though.

How do you choose dash direction then since the character no longer rotates?

that’s what I’m confused about, idk how to do that

Okay, you can take not one but two axis of the last input vector into account :slightly_smiling_face:

And the more optimal option, storing the direction according to the movement input actions is still there. Again, just use both the forward & right movement input actions (or you might have single movement input action with a 2D vector as well, in that case again, take the both axis into account)

And btw

Just remembered that the input vector is not a unit vector so check if it’s components are greater or less than 0 rather than checking if they’re 1 or -1

I mean - how do you choose, as the player, what direction to dash:

  • do you dash towards the mouse cursor?
  • do you dash in the direction you are moving?
  • do you dash towards a selected / closest enemy?

It is decided, somehow, right? Your post does not state the logic behind it.

oooo okay sorry, the player dashes in the direction they are moving in

Then @VisAgilis has answered your question. Either:

  • use Get Last Movement Input Vector node
  • or use the direction the Input Action node spits out
  • or you can use Normalised player Velocity if you’re using Pawn with a Movement Component or utilise physics
1 Like