How do I make my character face the direction of the movement?

0 favourites
  • 5 posts
From the Asset Store
Rotate & Animation for 16 Direction & Mouse Direction
  • When I press the A button, then quickly press the D button, and then release the D button, my character starts to run left while facing right. And vice versa: When I press the D button, then quickly press the A button, and then release the A button, my character starts to run right while facing left. Maybe someone knows how to fix this. My code for the player's movement looks like this:

  • I don’t know why you are using "On Pressed A and D" — perhaps you are creating some other function. However, the reason why your character moves left with its face facing right when you press A, then D, and release D is that the last key you pressed was "D." The `onPressed` function executes immediately upon pressing a key, so after pressing A and then pressing D, the `mirror` function for A will be overridden by D, and vice versa.

    However, for the down function, if A and D are pressed simultaneously, the character will not move because one is moving right and the other is moving left. But when you release D, the character will walk because of the key A, although the appearance will still not be mirrored due to the last pressed key being D.

    Initial state: Mirror - Not WALK

    Press A: Mirror(onPressed) - WALK to Left(KeyDown A)

    Press D: NotMirror(onPressed) - NOT WALK (because walk to left and right) (KeyDown A and KeyDown D)

    Release D: Still NotMirror (because the last onPressed is D) - Walk to left (because keydown remains A)

    So your character will face right (NotMirror) because your last pressed key was D.

    This is my simple solution.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thank you, it worked! There was no specific reason for using "On Pressed...". I'm still learning, so it was one of many mistakes.

  • Sometimes the movement of a character's face doesn't have to match the same direction the character is moving. You could try actions like jumping or walking to the left while shooting or attacking to the right, so the character will face right while moving left.

  • That's interesting, thank you. In my current project, my character can't shoot. But it's a good idea for a future project

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)