Forum rules - please read before posting.

Getting A* Pathfinding Project Pro to work with Adventure Creator.

edited March 2014 in Technical Q&A
Anyone have any ideas if any tutorials exist for this?

Comments

  • Hi!Support for other navigation techniques was added in 1.20:
    Added: NavigationManager and subclasses - to make a new navigation method, just add to the enum and create a subclass
    Chris has given some more advice on this topic in the old forum thread here:http://forum.unity3d.com/threads/204414-Adventure-Creator-Make-3D-adventure-games-(DEMO-VIDEO-WEBSITE

    Unfortunately I wasn't able to find the post anymore, but maybe you can find it yourself using "NavigationManager" or Pathfinding as search terms.

    Good luck!

    orrence.




  • edited March 2014
    There aren't tutorials, because every case will be different.  However, the basic steps are:
    1. Create a script called NavigationEngine_AStar, and make it a subclass of NavigationEngine.
    2. Edit Enums.cs and add AStar into the AC_NavigationMethod enum definition.
    3. Inside your new script, you will need the following override function:
    public override Vector3[] GetPointsArray (Vector3 startPosition, Vector3 targetPosition)

    You can add other code to your script, but this is what's used by AC to return a calculated path.

    With the script complete, you should be able to choose it in the Scene Manager's selection of pathfinding methods.
  • Thank you ChrisIceBox, you totally saved me hours!
  • No problem!  Feel free to share with the community if you get it working, I'm sure others would find it useful
  • Sure, if I get A* working with AC I'll make it into a sort of compatibility asset and post it somewhere around here.  You should totally make a category page for user-made modifications and resources for AC.
  • Good idea - "Extending the editor" added as a category
  • I really gotta get back into coding again, I've gotten so rusty and forgot such basic crap;  could you point out where I went wrong in this?  I have a feeling it must be something completely obvious, and maybe my sleep deprivation is the reason I'm not seeing it.

    image
  • using UnityEngine; 
    using System.Collections; 

    public class NavigationEngine_AStar : NavigationEngine { 
    public override Vector3[] GetPointsArray (Vector3 startPosition, Vector3 targetPosition) { 
     //YOUR CUSTOM CODE HERE! 
    }
  • Ah thanks, derp.
  • @Teirdalin : You wrote in a previous post: "Sure, if I get A* working with AC I'll make it into a sort of compatibility asset and post it somewhere around here."

    So what about it, were your efforts crowned by success?

    Cheers!
  • edited June 2014
    Hullo here it is :

    using UnityEngine;
    using System.Collections;

    public class NavigationEngine_PathPro : NavigationEngine {
    Seeker player;
    public NavigationEngine_PathPro()
    {
    player = null;
    }
    override public Vector3[] GetPointsArray(Vector3 startPosition, Vector3 targetPosition)
    {
    if (player == null)
    {
    player = GameObject.FindObjectOfType<Seeker>();
    if (player == null)
    {
    Debug.LogError("Can not path find, seeker script missing");
    return null;
    }
    }

    Pathfinding.Path path = player.StartPath(startPosition, targetPosition);
    AstarPath.WaitForPath(path);
    return path.vectorPath.ToArray();
    }
    }

    It's really rusty version as any game object in the scene could be randomly selected.
    Nevermind the warnings output by A.C mentionning the Unity Navigation system.

    Also as prerequisites : 
    - The player prefab must have at least a Seeker component attached to it
    - There must be a game object with the Pathfinder component
    - For now the mesh that receive raycasts must be set to NavMesh Layer, or AC will halt the calculation 
  • I think this integration is very important.

    ChrisIceBox  there is a way to use the mesh colliders on my "scene" and/or terrain for pathfinding with AC already?

    Since there are already meshes on all the scene objects (and a terrain) on other scenes, it should just be able to walk to the point clicked there? 

    I'm using direct to cursor movement 3D.

    Thanks
  • If you want to navigate a terrain, either bake a Unity NavMesh or export the terrain's mesh to a 3D tool, remove the vertices where you don't want characters to move, and re-import it as NavMesh to use with the MeshCollider method.
  • Okay,

    What if the scene level is made out of meshes already, all I have to do is set them in the layer NavMesh and the character should simply acknowledge and move to that point clicked? or do they have to be placed in the default NavMesh scene settings.


  • Yes - for MeshCollider pathfinding to work, the active NavMesh has to be known by the Scene settings, and must be a single mesh.  You could either bake your NavMesh and use Unity Navigation, or merge your meshes into a single one using a 3D tool.
  • Hello, allow me to bump this old thread ! I'm trying to use A* with AC, to no avail so far. I decided to take things one step at a time and start with a simple cube NPC with no rigidbody orderded to move to a marker - A* is indeed called and the cube follows a path to to the marker, but cannot simply reach the point and stop there, and instead tends to move slightly around the target and rotate on the y axis in a jittery way.

    I confirm that A* works as expected without AC and that the cube can otherwise stop at the marker, and I pretty much copy-pasted Salepaste's script - the WaitForPath function is now deprecated though and must be replaced with BlockUntilCalculated.

    Has anyone successfully integrated A* in AC, or at least managed to simply send a basic NPC to a marker as I described ? Thanks in advance !

  • If you're still using AC to handle the character's motion once a path has been calculated, they still abide by AC's various movement settings.

    If the character is spinning around the final node, it may be that you need to lower the "Destination accuray" slider in the Settings Manager, or enable "Retro-mode pathfinding" on the character's Inspector.

    See the Manual's "Precision movement" chapter for more on this topic.

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.