How to flip when an object is moving in a particular direction

This is my scene

My object will move to a position where ever the mouse clicked or on touched(in mobiles). There are no arrows like right, left, top, bottom. Also there is no use of any keyboard buttons. Only touch/click is there.
I added animation when it’s moving. I also want to flip it horizontally when it is moving towards right direction. And if it moves left, i want to flip horizontally again.
Any help would be really appreciated.

It is sounds like you need 8 direction animation/movement, I did share an example here.

The concept is the same if you need only 2 directions, left and right…

1 Like

This helped me in drawing line from object to where ever we click on the scene. I made some changes to hide the line after the object reaches the destination. But if the object is moving along the path, the line behind the object should not show.


How can we achieve this?
And also the directions are still not working for me for some reason. I doubt, i made some silly mistake somewhere.

@ddabrahim can u please help me with this?

Sorry, I don’t have time to help you with the implementation right now.
The idea in the example is that you have 2 objects, an invisible object move on the path and rotate and the actual sprite object follow the invisible object and you check the angle of the invisible and change the animation and flip the sprite according to the angle of the invisible. This is because you don’t actually want to rotate the sprite, so in the example we rotate the invisible object instead…

For you it is maybe way too overcomplicated actually. If all you want to know if the sprite is moving left or right maybe more simple to check the X position of the destination of the path.

If destination X >= the Jerry.X() then flip Jerry right
If destination X <= the Jerry.X() then flip Jerry left

The expression to get destination X is:
ObjectName.Pathfinding::DestinationX()

Hey, it was fixed. Thanks for trying to help.

Great, next time maybe let people know so nobody wasting their time trying to help you while you no longer looking for a solution.
If it was something tricky and not just your lack of experience it is also useful to share what was the obstacle you experienced so others can learn from it too. :+1:

This is the solution i came across. @Ruhan helped me with this solution.