Seeker don't know how to avoid obstacle

  • A* version: 4.2.17
  • Unity version: 6000.0.38f1

dsadsada

Sorry for bothering you, I’m doing 2D game and I need to implement AI Pathfinding, I found your package and it’s pretty good for me, my obstacle is spawned during playing mode and I updated the graph for its position

However, problem here that my seeker keep moving forward although there is a obstacle in front of him instead of dodge/move around the obstacle, he should know how to dodge the obstacle and find other way

Tried many ways with Seeker.StartPath, AIPath.SearchPath, but the result still the same.

Here is my NPCController.cs

            if (_aiDestinationSetter.target != null)
            {
                _aiPath.destination = _aiDestinationSetter.target.transform.position;
                return _aiPath.desiredVelocity;
            }
            return Vector2.zero;

Spawner.cs

        private void UpdatePathfindingGraph(GameObject go)
        {
            if (Pathfinder == null) return;

            // skip only the types you really want to skip
            if (_type == SpawnerType.BUSH || _type == SpawnerType.CROP) return;

            Vector3 newPosition = go.transform.position;
            if (go.TryGetComponent(out TreeObject treeObject))
            {
                float offsetY = 0;
                // Down the position for bottom tree
                if(treeObject.type == TreeObject.Type.THIN)
                    offsetY = 0.5f;
                else if (treeObject.type == TreeObject.Type.NORMAL)
                    offsetY = 1f;

                newPosition.y -= offsetY;
            }

            Bounds b = new Bounds(newPosition, Vector3.one);

            // do a proper GraphUpdateObject with physics
            var guo = new GraphUpdateObject(b)
            {
                updatePhysics = true,
                modifyWalkability = true,
                setWalkability = false,
            };

            AstarPath.active.UpdateGraphs(guo);
        }

I’d try making the bounds a little bigger? I did some playing around with all this on my end and that’s probably what I’d suggest trying here first. Make sure it fully encapsulates the area you want to change rather than being exactly the same size of it, for precaution sake.

Thanks for the suggestion! I changed the node size to 0.5 and set the collision diameter to 1.25. I hadn’t read the documentation carefully about AILerp, but after adding it, my NPC is moving a lot smarter than before. Just need a few tweaks to the modifiers, and I think it’ll work perfectly.

1 Like