Question: RichAI to specific Graph

–==TRANSLATOR==–
Hello, there is a way for “RichAI” to be in a certain “Graph”?
Thank you for your attention.

–==ESPAÑOL==–
Hola, hay forma de que “RichAI” este en un determinado “Gráfico”?
Gracias por la atencion prestada.

Hi

Yes it is possible.
It is not possible out of the box with the current movement scripts, but it is a very easy fix.
You do it by passing the graphMask parameter to the seeker.StartPath method.
See https://arongranberg.com/astar/docs/class_seeker.php#ab50a876ab529ceb3eb9b97deb5a48d1e
This is a bitmask, see https://www.arongranberg.com/astar/documentation/dev_4_1_7_6425cc50/bitmasks.php

1 Like

Could you give me an example?

–==ESPAÑOL==–
Buenas tardes.
Tengo este código hecho y me gustaría agregarle soporte a GraphMask.
La duda seria como agregar este soporte y que permita calcular constantemente la ruta.
hay alguna forma directa de definir en cual GraphMask está trabajando?
Gracias por la atención prestada.

–==TRANSLATOR==–
Good afternoon.
I have this code done and I would like to add support to GraphMask.
The doubt would be how to add this support and allow to calculate the route constantly.
Is there any direct way to define which GraphMask is working on?
Thank you for your attention.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Pathfinding;

[RequireComponent(typeof(Seeker))]
public class CharacterBotAI : AIPath
{
    public GeneratePoints generatePoints;
    public Transform targetPosition;
    public bool isFinishDistance = false;
    public float distance = 2;

    public Animator animator;
    public float sleepVelocity = 0.4F;
    public float animationSpeed = 0.2F;

    private IAstarAI ai;

    new void OnEnable()
    {
        base.OnEnable();
        ai = GetComponent<IAstarAI>();
        if (ai != null) ai.onSearchPath += Update;
    }

    new void OnDisable()
    {
        base.OnDisable();
        if (ai != null) ai.onSearchPath -= Update;
    }

    public new void Start()
    {
        base.Start();
        
        targetPosition = generatePoints.ListGameObject[Random.Range(0, generatePoints.ListGameObject.Count)].transform;
    }

    public override void OnTargetReached()
    {
        if (!isFinishDistance && targetPosition != null && Vector3.Distance(tr.position, targetPosition.transform.position) > endReachedDistance / 2)
        {
            targetPosition = generatePoints.ListGameObject[Random.Range(0, generatePoints.ListGameObject.Count)].transform;
            Debug.Log("Llego " + this.name);
        }
    }

    protected override void Update()
    {
        base.Update();

        if (targetPosition != null) ai.destination = targetPosition.position;

        if (isFinishDistance && targetPosition != null && Vector3.Distance(this.transform.position, targetPosition.transform.position) < distance)
        {
            targetPosition = generatePoints.ListGameObject[Random.Range(0, generatePoints.ListGameObject.Count)].transform;
        }

        Vector3 relVelocity = tr.InverseTransformDirection(velocity);
        relVelocity.y = 0;

        if (relVelocity.sqrMagnitude <= sleepVelocity * sleepVelocity)
        {
            animator.SetFloat("Blend", 0);
            animator.speed = 1;
        }
        else
        {
            animator.SetFloat("Blend", 1);

            float speed = relVelocity.z;
            animator.speed = speed * animationSpeed;
        }
    }
}

.

Hi

For this you can override the SearchPath method:

/** \copydoc Pathfinding::IAstarAI::SearchPath */
public override void SearchPath () {
	if (float.IsPositiveInfinity(destination.x)) return;
	if (onSearchPath != null) onSearchPath();

	lastRepath = Time.time;
	waitingForPathCalculation = true;

	seeker.CancelCurrentPathRequest();

	Vector3 start, end;
	CalculatePathRequestEndpoints(out start, out end);

	// This is where we should search to
	// Request a path to be calculated from our current position to the destination
	int graphMask = 1 << 2; // Or something
	seeker.StartPath(start, end, null, graphMask);
}

Muchas gracias por la pronta respuesta aron
Solucionaste mi problema.