Support Forum

New position of target

Hello everyone!

I have been using A* Pathfinding recently and I don’t understand many things yet. I am making a simple game and most of the systems I have already made, some based on this system (it’s brilliant!) But I have one little problem and I have no idea how to solve it.

I have a player in my scene with the components: “Seeker”, “AiPath (2D, 3D)” and “AI Destination Setter (Script)”. Also, I have a “Target” with a “Target Mover” component. Everything works fine here, after clicking somewhere on the map, the player easily approaches it.

I added an object to the scene, let’s call it “Item”. After clicking on it, I would like the player to approach a specific XYZ on the map. For this, “Item” changes the position of the “Target” object. Unfortunately, after changing the target position, the player sprite will not budge! I tried to copy the content of the “Target Mover”, I tried to bind the “Item” object script to the “Pathfinding” namespace, and many, many other things, but I run out of ideas and can’t find anything in these systems that pushes the player to move or blocks this movement .

I will add that after the item changes the position of the target, the player will not move, but when I click somewhere, it obviously follows the mouse.

I would be very grateful for your help, I have run out of ideas.
Thank you in advance!

This is the answer. The script is triggered after the mouse is pressed, not after changing the position of the object.

1 Like

I understand. How then to trigger the script to make the character move?

Without seeing the code and the scene, I can only guess. I’m not that good a programmer, that’s why I’m sitting here on the forum.
https://arongranberg.com/astar/docs/targetmover.html

bool onlyOnDoubleClick

Try the opposite value.

1 Like

Unfortunately, when “onlyOnDoubleClick” is turned off, the target position is always the same as the mouse position and the character does not move at all, even if I click.

I didn’t mention it, but my project is 2D. I checked Example Scene 2D again and there, too, the character does not move at all when I turn “onlyOnDoubleClick” off.

In Example Scene Terrain everything works fine, but this scene is in 3D…

OK, I already know what the problem is! Automatic path calculation should be set in “AI Lerp” (default is “never”). I sat on it for a few days and only now noticed it XD
Now everything works as it should

Thank you for your help (I’m looking at you RikiTikiTak)!

2 Likes