New target script change

I just updated to the 4.1.10 patch (so far I’m liking it!), (I also haven’t used A* in a long time so I’m catching up) and I have a small issue that I was hoping could be easily fixed.

Since the new AIDestinationSetter script allows for the targeting to be slightly different than before, I am trying to set the target destination with a raycast. I am sure there is a script out there that works, but for the life of me I can’t figure out how to send the hit.point of a raycast to the AIDestinationSetter script. Is there a way to do this or should I just add the raycast script into the AIDestinationSetter script?

Mostlt what I am hoping to do is use A* for a multiplayer game. It seems like it would be easier to have each individual player grab the coordinates of a verctor3. I am wondering if I have to make an empty object to be a target if each player will be able to have their own target (I know its possible, it just feels like more work)


If you are trying to set it using a Vector3 you can skip the AIDestinationSetter component altogether.
Just use

var ai = GetComponent<IAstarAI>(); // AIPath/AILerp/RichAI script
ai.destination = hit.point;

And make sure that you have removed the AIDestinationSetter component.

Works perfectly! Thabks so much!

One final small adjustment, how do I make my player move to the center of each node, or the center of the nearest node, rather than moving to the exact point where I click? I remember setting it up with the older version but I can’t find how I did it. Any help at all would be great!


Simply set Seeker -> Start End Modifier -> End Point to ‘Snap To Node’.

I actually tried that, but it doesn’t seem to make a difference. I can still click on any location and my player will move to the point clicked, not to the center of the nearest node. Is there another spot I should be checking?

Huh. No that should be everything you need to do. How does the calculated path look (enable Seeker -> Draw Gizmos)?

That’s what I thought, but it isn’t working. I know in the older version it worked just fine.

I have Draw Gizmos set to on, and have tried all possible combinations for start and end point snapping. A line is still drawn, but it foes not move through

Actually I may have figured out my issue. It appears my models are all much larger than the scale for the grid of the A*. I’m going to try scaling things down or the grid up and see if that works

Yup, that was it. I just needed to increase the node size to 2 and adjust the world position and it all worked just fine! Thanks for the help!

1 Like