Forum rules - please read before posting.

How to get transform of the end node in a path?

To be more specific, I need to get the world/scene transform position vector3 of the end destination node in a path generated when I mouse click to move the player character.

I'm trying to make a homemade Spine animation integration, so a way to know the point of destination of a given toon would be priceless to my ends.

Thanks.

Comments

  • edited September 2016
    Umm... I was looking at the API and I think maybe this method would be useful:

    AC.NavigationEngine.GetPointsArray ( Vector3 startPosition,
    Vector3 targetPosition,
    AC.Char _char = null


    Basically the first position would be the character's transform and the target would be where the mouse was clicked. The method then returns an array of vectors which represent the path, so the first one would be the origin and the last one would be the end point! AC is probably using this same method to calculate the character's path so it should probably return a similar result. Still, let's see if Chris has a built in variable which stores the data, else we could try this.

    Edit: there's also a Polygon collider version if that helps:

    AC.NavigationEngine_PolygonCollider.GetPointsArray ( Vector3 startPosition,
    Vector3 targetPosition,
    AC.Char _char = null

  • edited September 2016
    Thanks for taking your time, and that's promising Alverik. :)

    To be honest, what I firstly tried to find was some exposed property related to the player facing direction when moving, which is what I actually want to know so I can pass that data to a PlayMaker script and switch an animation flip state accordingly...

    But I suspect that my little previous trick of setting the player rotate speed to 0, so its mesh doesn't rotate as well when moving around, is gonna make impossible to return a valid value... if it doesn't rotate, then it's value won't change, I think.

    So that's the reason I'm trying now to find out where the end node of the path is, so I can face the player in that direction just as it starts moving. Not very elegant but I would like to avoid needing to use a Mouse Pick event because in that case I'd need to cover the whole scene with an annoying collider and configure every other element which overlaps with it in some way to block those clicks.

    And yes, I'm sure I'm not doing things the elegant way... :-D

    Edit: I forgot to mention that I tried to make use of that method you mentioned in NavigationEngine_PolygonCollider, but as it is a script located in the project assets, and it's not up in the hierarchy, I don't know how to call it because I only understand PlayMaker to some useful degree, and I cannot drag & drop that object in PM unless it's attached to some game object. :(
  • A Character's pathfinding nodes are stored in their own Paths component in the form of the nodes List.  However, the Player and NPC scripts have an easy way to extract the last node for you: GetTargetPosition, i.e.:

    AC.KickStarter.player.GetTargetPosition ()
  • edited September 2016
    Nice, so navigation just creates a Path under the hood? I though that was only for the Paths you can create in the editor. That'll be useful information :)
  • Thank you Chris! I hope I can get my hands dirty with that nifty function today...  :D
  • @Anaxtasia: You're welcome!

    @Alverik: Yeah, the Paths component serves a dual-purpose.  If you add it to a Player or NPC the regular Inspector controls get hidden - it's not the most elegant solution, but it does mean you can read/write it through script easily.
  • Just had the time to test it... and it works like a charm! Now's far more elegant and efficient.  :)>-

    Thanks!
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.