Forum rules - please read before posting.

SetPath with pathfinding to the path first node

Hello, when using SetPath() by script, is there a way to ask the character to go to the first node by pathfinding?

Otherwise, if I use MoveToPoint() before SetPath(), how do I do a wait til finish option in MoveToPoint() by script so that SetPath() will only execute after the character is close to the path first node?

Thanks.

Comments

  • is there a way to ask the character to go to the first node by pathfinding?

    If you were doing this with Actions, you could queue up a Character: Move to point Action followed by a Character: Move along path. If you mapped the fields to parameters, you could set the parameter values through script and run it from there.

    Through script only, you could try tackling it with a coroutine to wait for the player to finish moving to the first position, but you'd be best off incorporating the dynamic path to the first path, and the pre-set nodes of a second path, into the player's actual motion.

    Vector3 pointsToFirstNode = KickStarter.navigationManager.navigationEngine.GetPointsArray (KickStarter.player.transform.position, myPath.nodes[0], KickStarter.player);
    Vector3 pointsAlongPath = myPath.nodes;
    
    Vector3 totalPoints = // Some algorithm to combine the two above
    
    KickStarter.player.MoveAlongPoints (totalPoints);
    
  • edited December 2018

    Thanks for the tips. Just to share my finding: as my MoveToPoint() is also in the coroutine, I used these codes to achieve the desired effect:

    while (thisNPC.IsMovingAlongPath ())
    {
    yield return new WaitForFixedUpdate ();
    }
    thisNPC.SetPath();

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.