Hello all,I’m making a 2d top down game and I’m making an A* AI for the enemies based on a node system. I made a very simple function too smooth the path found by reducing the number of nodes to follow, given the node i if i “sees” i+2 delete i+1. that’s the code:
void SmoothPath()
{
for(int i=0;i<closed_list.Count;i++)
{
if (i + 2 < closed_list.Count)
{
RaycastHit2D ray = Physics2D.Raycast(closed_list*.transform.position, closed_list[i + 2].transform.position,*
Mathf.Infinity);
if (ray.collider != null)
{
if (ray.collider.gameObject==closed_list[i+2])
{
closed_list.Remove(closed_list[i + 1]);
Debug.Log(ray.collider.gameObject.name);
}
}
}
closed_list*.GetComponent().color = d;
_}_
_}*_
The problem is that the if is never true even if i+2 has surely been hit because in this list of nodes (closed_list) every node, as you can see in the cycle, casts a ray towards the node after its adjacent node. But it doesn’t execute the if. Instead if I use ray.collider.gameObject.tag=="node" the if is executed but it doesn’t do what it should do. I also tried with GetInstanceID() but nothing. I’m pretty sure it’s a stupid logic error I’m making. What’s wrong? Thanks in advance ![]()