A* Pathfinding Project

Getting the next node in a path


#1

How do I get the next node in a path. I’ve pretty much got things working by setting penalties in the grid for movement, but sometimes for some reason, my enemy passes right thru colliders, so I’m thinking if I get the penalty for the next node in the path, I can use that to tell it when to stop and destroy the obstacle that’s there.I’m using the AI Lerp move script for movement, if that makes a difference


#2

Hi

For this you currently have to make a subclass of the AILerp script.
Something like this

class MyAILerp : AILerp {
	public override GraphNode NextNode {
		// Note: Doesn't do any bounds checking, you should probably add that
		// Also only works if you don't use any modifiers that e.g smooth or simplify the path
		return path.nodes[interpolator.segmentIndex+1];
	}
}

I haven’t tested this, but I think something like that should work.


#3

Awesome. I’ll give this a shot and see what happens!


#4

I’ve never worked with inheritance before so this is like a nightmare for me. Apparently, path.nodes doesn’t exist? The error I get is "ABPath does not contain a definition for nodes, and no extension method ‘nodes’ accepting a first argument of ABPath could not be found.


#5

Ah. Sorry, it should be path.path not path.nodes.


#6

Cool. That took care of that error. Still struggling with this quite a bit tho. What am I supposed to put in to be overridden? All I want is the penalty for passing thru its next waypoint cuz using a ray or collision to stop him when he hits a wall in his way, the enemy occasionally just passes right on thru. Most of the time collision works, but not every time.


#7

I think I got the raycast to work. Execution order problem


#8

nope that wasn’t it lol


#9

Ah, right. It shouldn’t be an override there either as you aren’t actually overriding any property.
Sorry for all the typos.


#10

AWESOME!! That helps. Yea I just had ,my friend over yesterday and he kinda said the same thing. What really sucks is it happens sooooo rarely, nut in my head, if it happens once, that’s enough