A* Pathfinding Project

Local avoidance for non-instantaneous velocity change


#1

Hi,
I am on the free version.

I am currently working with Behaviour Designer Formation + A* Pathfinding project where I’m simulating multi-quadcopter formations with the help of an external simulator.
I send roll-pitch-yaw-throttle values to the simulator.

Everything works fine for now, but I want to start using some form of obstacle avoidance.
I’m not sure if RVO is best suited for this.

I’ve written a custom movement script inheriting from IAstarAI, this send the calculated roll-pitch-yaw vales to an externally interfacing controller which then reads in positing and rotation data from the simulator and update the transform accordingly.

I’m adding the update loop below, it’s mostly adapted from your tutorials.

What would be the best way to implement local avoidance.
Thanks.

(Apologies if there’s too much information here)

public void Update()
    {
        if (path == null)
        {
            // We have no path to follow yet, so don't do anything
            return;
        }

        // Check in a loop if we are close enough to the current waypoint to switch to the next one.
        // We do this in a loop because many waypoints might be close to each other and we may reach
        // several of them in the same frame.
        reachedEndOfPath = false;
        // The distance to the next waypoint in the path

        while (true)
        {
            // If you want maximum performance you can check the squared distance instead to get rid of a
            // square root calculation. But that is outside the scope of this tutorial.
            distanceToWaypoint = Vector3.Distance(transform.position, path.vectorPath[currentWaypoint]);
            if (distanceToWaypoint < nextWaypointDistance)
            {
                // Check if there is another waypoint or if we have reached the end of the path
                if (currentWaypoint + 1 < path.vectorPath.Count)
                {
                    currentWaypoint++;
                }
                else
                {
                    // Set a status variable to indicate that the agent has reached the end of the path.
                    // You can use this to trigger some special code if your game requires that.
                    reachedEndOfPath = true;
                    break;
                }
            }
            else
            {
                break;
            }
        }

        // Direction to the next waypoint
        // Normalize it so that it has a length of 1 world unit
        Vector3 dir = (path.vectorPath[currentWaypoint] - transform.position).normalized;

        //calculate roll pitch yaw
        Vector3 localTarget = transform.InverseTransformPoint(path.vectorPath[currentWaypoint]).normalized + delta;
        targetAngleYaw = Vector3.SignedAngle(dir, transform.forward, Vector3.up) / 45; 

        if (Mathf.Abs(targetAngleYaw) < 0.1 || reachedEndOfPath || Mathf.Sqrt(distanceToWaypoint / nextWaypointDistance) < 0.08f)
        {
            targetAngleYaw = 0;

        }
        else
        {
            targetAngleYaw = -targetAngleYaw;
        }
      
        // adjust the yaw and pitch towards the target
        //controller.Move(localTarget.x, localTarget.z, -targetAngleYaw);
        if (!controller.lookTowardsPath)
            controller.Move(localTarget.x * speed * maxSpeed, localTarget.z * speed * maxSpeed);
        else
            controller.Move(localTarget.x * speed * maxSpeed, localTarget.z * speed * maxSpeed, targetAngleYaw * speed * maxSpeed);

    }

#2

Hi

RVO is unfortunately particularly ill suited for this as one of the explicit assumptions that that algorithm makes is that all agents have an infinite acceleration. I would suggest that you look into things like boids instead (see https://www.red3d.com/cwr/boids/).