Seeking alternative to : Unity's NavMesh.Raycast

Hi there,

I really like the work you are doing in this great project.

So far I am migrating from Unity’s NavMesh to A* pathfinding.
I stuck on something, and tried to search the forum and Google and reached nowhere,

I need to do a raycasting to get the first walkable node,
with NavMesh, I would do something like this :

NavMeshHit hit;
if (NavMesh.Raycast(transform.position, target, out hit, NavMesh.AllAreas)) {
	target = hit.position;
}

I am bit confused a bout what should I do using A* Pathfinding Free version
and I am using GridGraph.

Also would like to mention that I need that node to do a Dashing effect ( without passing through the walls )

Thanks in advance.

If someone come seeking the same answer,

I partially solved the issue by using Physics.Linecast ( you can use Raycast too )
I still need a more thing, to find the first walkable node to move to, so far I don’t pass walls, But for a second it collides into the wall then animate moving to the first walkable point.

public Vector3 RayCast(Vector3 target){
	Vector3 origin = transform.position;
	origin.y = target.y;

	RaycastHit hit;
	if (Physics.Linecast(origin, target, out hit)){
		target = hit.point;
	} else {
		return target;
	}

	target.y = origin.y;

	return target;
}

Hi

You can use GridGraph.Linecast

GraphHitInfo hit;
var graph = AstarPath.active.astarData.gridGraph;
if (graph.Linecast(transform.position, target, null, out hit)) {
    target = hit.point;
}

This feature is only available in the pro version however.
If your colliders are accurate enough you can use Physics.Linecast as a replacement.

Perfect,

This is very good news !
We intend to purchase the Pro version soon,
I believe it will give me the most accurate result.

So far, I solved the issue using ( a very bad hack - but doing the job)

if(AstarPath.active.GetNearest (target).node.Walkable){
	target = (Vector3) AstarPath.active.GetNearest (target).node.position;
}else{
	target = target + 2 * (origin - target).normalized;

	if(AstarPath.active.GetNearest (target).node.Walkable){
		target = (Vector3) AstarPath.active.GetNearest (target).node.position;
	}
}

Thanks Aron,

1 Like