Direction problem

So my character is supposed to face whatever direction he’s walking, And he does. But when you hold left/right, and then up/down, he still faces left/right. What’s weird is that this isn’t an issue when holding up/down and then left/right.

Here are my events:

So you end up holding 2 keys at the same time; one of left/right and one of up/down?

Then that’s perfectly logical. You events are processed from the top, not the order in which you press the keys.

If you hold left and up, the up key gets processed first, setting the direction variable to 1. But, immediately after that the left key is processed, changing the direction variable 2. The left keypress always overwrite the up/down keypress.

How do I make it so that it’s balanced?

What do you mean by balanced?

You how the animation always changes whenever you hold up/down and then left/right?

I want the same with the other way around. (left/right then up/down.)

I don’t want him walking sideways.

A way could be to test for two keys pressed (Up and right):

  • If Key Up is pressed
  • If Key Right is pressed
  • Once when true Scene Variable(dir) = RandomInRange(0,1)
    + If Scene Variable (dir) = 0 then Lyrod variable direction = 1
    + If Scene Variable (dir) = 1 then Lyrod variable direction = 3

This way sometimes it will be up, sometimes it will be right, but of course, it will add some events to your sheet since it must be done for each diagonal.

Personally I don’t use it. It seems to be to much. For what I can notice, maybe to allow diagonals could be better for the overall looking of the walking.

A suggestion to handle the animations, if you want to try it, is to add a string variable to your character (Status) and put in it values for “move” and “idle”, with this variable, and the value of the angle the character is moving, you can change animations with a single event.

Player.VariableString(Status)+ToString(round(Det_Jugador.TopDownMovement::Angle()/90)*90) ← This is the event I use to handle animations. My animations are named “idle0” (right), “idle90” (down), “idle180” (left), “idle-90” (Up), and “Walk0”… etc.

Another way is to enable the 8 directions, but it means you need to make the animation for each direction too.

I changed the events from using variables to the angle of movement. That fixed it. Thanks for all of your help!

1 Like