I need a ton of help! Starting new

I am working on a very specific type of adventure game that requires the player to move along a grid, more specifically it is a click to move style movement. When a grid is clicked the player will navigate to that grid square and stay in the center of it, and when navigating to there will stick to straight paths from center of square to center of square (no smooth movement)

Now I’ve already downloaded the script and installed/created everything just fine. Where I am at right now is when I click a point on the ground the player navigates to that point, but he navigates to the point and not to the actual node closest to where I clicked. I’m not exactly sure how to locate a node because I’m not even sure what the script references as a node.

My second issue will come when I want to make an object that is useable, where the player has to navigate to the object then use it. I have no idea how to make the player navigate to the nearest node rather than into the object itself.

I realize this is a lot to ask for in terms of help, but coding is just not my thing. I’m surprised I even made it as far as I did. Any help at all from anyone would be great!

Hi

Here is another movement script which just uses lerping. That might be better for you game: http://pastebin.com/tAsRFKyF

As for moving to the center of a node, check out the StartPoint and EndPoint fields in Seeker->Start End Modifier.
You can get the closest node of a point by calling AstarPath.active.GetNearest (…) (see documentation for more information).

I’ll definitely have to check out that script later!

Ah silly me, somehow I missed that part of the documentation about the node snapping. I just set it to snap to nodes and had to adjust the distance that it stops at a node and it seems to work perfectly!

I did see the documentation on finding the nearest node, unfortunately it makes very little sense to me. I will try to wrap my head around it again later though, for now I’m going to tweak the movement.

Thanks for all the help!

Ok. Good luck.

What doesn’t make much sense? Maybe you can suggest improvements to the documentation?

Thanks! Good idea, I’ll throw out what I have here and see what I can figure out. So I have this line or two from the reference site

GraphNode node = AstarPath.active.GetNearest (transform.position).node; if (node.Walkable) { }

this all seems pretty basic and easy. If I use this code it finds the nearest active node to my player (and if its on the layer walkable I can do stuff) My problem seems to be when I try to actually use the code, its in the wrong place or I’m using it wrong.

I have this section of my code that is tag checking and determining if a player can move or not, it exists outside the actual pathfinding section of the movement code which may be my problem but I’m not sure yet.

[CODE]if (Input.GetMouseButtonDown(0))
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(ray, out hit))
            {
                targetTransform = hit.transform;

                if (hit.transform.tag == tagCheckwalkable)
                {
                    targetPosition = hit.point;
                }
                if (hit.transform.tag == tagCheckuseable)
                {
                    
                }

[/CODE]
So far this has worked perfectly for the player moving to another walkable node. Now I want to click on a useable object and have the player move to the square next to it, and I can’t just add in the line of code I mentioned at the start of this post because it all exists outside of the pathfinding section of code. When I do just drop that line of code in, everything works fine until I click my useable object, then my player just stops moving all together and won’t move anymore no matter where I click.
Do I simply need to move it all within that part of the code? Or is there some heavier adjusting I’ll have to do?

Hi

If you set the target of an agent to some point it cannot reach, it should try to move to the closest point it can reach.
What is the path result when the agent stops moving? (See A* Inspector -> Settings -> Path Log Mode).

Path log mode is set to normal, but I’m not too sure what I am looking for. I sort of got it to work, the player now moves to a close node some of the time. It seems kind of random when it works to be honest. I’m wondering if I should just set it so if there is no path the player does not move. Is there an easy way to do that?

Hi

When searching for a node to move to, it will search for nodes it can reach up to a maximum distance around the target point. This distance is A* Inspector -> Settings -> Max Nearest Node Distance. Set that to a low value to make sure it will just report path failure if the target point was not walkable.

You could also check that before searching for the path.

var closestToUs = AstarPath.active.GetNearest(transform.position, NNConstraint.Default);
var closestToTarget = AstarPath.active.GetNearest(targetPosition, NNConstraint.Default);
if (PathUtilities.IsPathPossible(closestToUs.node, closestToTarget.node)) {
    // It is possible to go from our position to the target position
}