Flip enemy direction pathfinding

Hey guys, I need your help again. I have some enemies with pathfinder movement that automatically move around the map. I want them to turn right and left based on the direction they’re going, regardless of the player position. They only have to turn on the x asix. It could be a silly thing but I’m going insane! Thank to anyone that will help me

Don’t feel bad because this is actually much harder than it seems.
I had to figure this out for my game TripleJump on the overworld map.

I’ll hook you up with what I found works:

The trick is that the pathfinding logic breaks the path into nodes, and each node in the path could potentially change the direction that your object will be moving, so you have to break it down to the node level to figure out each step along the way which direction you are moving.

It took me a really long time to figure this out… so much moon-walking along the way :sweat:

Here’s a code block you can cut and paste in because those events may not make sense to you or others tackling this:
{"000kind":"GDEVELOP_EventsAndInstructions_CLIPBOARD_KIND-jsBdHbLy912y8Rc","content":{"eventsList":[{"disabled":false,"folded":false,"type":"BuiltinCommonInstructions::Standard","conditions":[{"type":{"inverted":false,"value":"PathfindingBehavior::PathFound"},"parameters":["PlayerHitBox","Pathfinding"],"subInstructions":[]},{"type":{"inverted":true,"value":"PathfindingBehavior::DestinationReached"},"parameters":["PlayerHitBox","Pathfinding"],"subInstructions":[]}],"actions":[],"events":[{"disabled":false,"folded":false,"type":"BuiltinCommonInstructions::Standard","conditions":[{"type":{"inverted":false,"value":"Egal"},"parameters":["PlayerHitBox.Pathfinding::NextNodeIndex()",">","0"],"subInstructions":[]},{"type":{"inverted":false,"value":"Egal"},"parameters":["PlayerHitBox.Pathfinding::NextNodeIndex()","<","PlayerHitBox.Pathfinding::NodeCount()"],"subInstructions":[]}],"actions":[],"events":[{"disabled":false,"folded":false,"type":"BuiltinCommonInstructions::Standard","conditions":[{"type":{"inverted":false,"value":"Egal"},"parameters":["PlayerHitBox.Pathfinding::GetNodeX(PlayerHitBox.Pathfinding::NextNodeIndex())","<","PlayerHitBox.Pathfinding::GetNodeX(PlayerHitBox.Pathfinding::NextNodeIndex() - 1)"],"subInstructions":[]}],"actions":[{"type":{"inverted":false,"value":"FlipX"},"parameters":["Player","yes"],"subInstructions":[]}],"events":[]},{"disabled":false,"folded":false,"type":"BuiltinCommonInstructions::Standard","conditions":[{"type":{"inverted":false,"value":"Egal"},"parameters":["PlayerHitBox.Pathfinding::GetNodeX(PlayerHitBox.Pathfinding::NextNodeIndex())",">","PlayerHitBox.Pathfinding::GetNodeX(PlayerHitBox.Pathfinding::NextNodeIndex() - 1)"],"subInstructions":[]}],"actions":[{"type":{"inverted":false,"value":"FlipX"},"parameters":["Player","no"],"subInstructions":[]}],"events":[]}]}]}],"eventsCount":1,"actionsList":[],"actionsCount":0,"conditionsList":[],"conditionsCount":0}}

3 Likes

thank you so much for your help

I also ran into this problem, I am currently using this event to be able to flip enemies based on their direction.

I tried to follow the post posted by krunkster above but it also has the same problem …

mine is a topdown game where the enemy chases the player very similar to a zombie game.

when the enemy runs after the player on the x axis and is in the center of the player they begin to vibrate, flipping horizontally continuously