How can I change the animations/ sprites of a pathfinding object

So my first ever GDevelop game is “Pending Publication” on the Google Play store now… I have a new game idea. It’ll be a click and go game where the character moves to the spot you clicked (or one could also use 8-directional buttons).

Now I wrote 2 line of “Code” that are not doing what I thought they would do. Not at all (See image above). The first event was suppose to make the player go to the touched/ clicked position (but its not doing that.

The second line was meant to change the animation when the player starts moving at a 90 degree angle. The idea was I’d have 8 different animations for 8 different possible angles. My first attempt isn’t registering.

Does anyone here have ideas?

If you need to see the project files, here they are. It’s all just placeholder sprites for now (Newscene2):

Here is an animated trailer of my first successfully completed game:
(Now I need help with my 2nd game)

@Totally2d Initially, try changing the “is equal to” = 90 for “is greater or equal to” >= 90 a common problem with this is that both position and angle happen over time and they are represented as “floating point numbers” so that condition will never trigger because the angle will NEVER be equal to the actual whole number 90. it might be 90.0000001 for all we know.

Also the player.Animation(1) value, is that a scene variable? if it is you need to wrap that inside the Variable(player.Animation(1)) expression otherwise the value will not be evaluated properly.

When there’s an error or non standard value, it should default to 0, which means the first sprite animation would be shown in your case, so it could be not working because of that as well. Just type out the number you need for an easy test.

If that doesn’t help or solve your initial issue, then try the same code but without pathfinding behavior, just using common conditions and actions, that is, just making the object move by using the move to position action and using the object own angle property to do a similar conditional check.

If it works, there could be a flaw in the pathfinding behavior that forbids you to check for the angle. If it still doesn’t work, there might be something else missing in your logic but it’s 3AM and I can’t see it :stuck_out_tongue:

Either way good luck!

1 Like

Move player to MouseX("",0);MouseY("",0)

I have Tryed to set the animation with angle >0/<45 >=45/<90 and so on. does not work. Pathfinding does not recognise angles well :frowning:

Here my events and I hope it helps you. If you want you can also apply animation and diagonal movements to the enemy.

It is my method but most likely there are other methods.

1 Like

I found a working solution. not a pretty one, but a working one.
i builded something like a compass.
Step1: First make a rectangle shaped object (thin and long, aka the needle.)
Step2: Set the needle = angle of the animated pathfinding object.
Step3: Setup 4 obects (or 8) for the directions and place them around the needle in a way that the tip is in collusion with one of the directions.
Step4: check collision from the tip of the needle with the direction object and then set the animation of your pathfinding object according to the collisions.
Place the compass outside screen or hide it.

Unnecessary stress for performance (especially if you need multible), but it works like a charm :slight_smile: