How do I animate NPCs that move with pathfinding?

0 favourites
  • 10 posts
From the Asset Store
Pathfinding AI
$0.50 USD
95% off
Units do not overlap each other and use different ways if there are several free ways.
  • Hey everyone, I want to add animations to my NPCs to walk up, down, left and right. I made their movement with Pathfinding since each one of them move to specific points in the map. Is there a way for me to make them play an animation depending on which axis they are currently moving for example? I know nothing about the coding aspect of it. Thanks in advance!

  • I was playing around with the pathfinding behavior trying to find a solution for this, and I discovered an expression (Sprite.Pathfinding.MovingAngle) which I didn't understand very well, because the value doesn't seem exact, but it should work for you.

    Here is an example: drive.google.com/file/d/1msNG-Z85tBGa6Yl7b5uEyOhD9R2A0lHB/view

    Now you just need to detect this value and set the animation accordingly, and that should be it!

    (;

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I was playing around with the pathfinding behavior trying to find a solution for this, and I discovered an expression (Sprite.Pathfinding.MovingAngle) which I didn't understand very well, because the value doesn't seem exact, but it should work for you.

    Here is an example: drive.google.com/file/d/1msNG-Z85tBGa6Yl7b5uEyOhD9R2A0lHB/view

    Now you just need to detect this value and set the animation accordingly, and that should be it!

    (;

    You mean I should look into ranges of their angle to change the animations accordingly. I need to look into how to program that but it's a great start, thank you!

  • you can use my project to test which number correspond with each direction, then use:

    detect angle <number you got from testing> -- set animation to <the animation you want>

  • you can use my project to test which number correspond with each direction, then use:

    detect angle <number you got from testing> -- set animation to <the animation you want>

    Yes thanks! I think I might have to do two detect angles for each zone to keep the range, I'll test it out. Thanks a lot!

  • you can use my project to test which number correspond with each direction, then use:

    detect angle <number you got from testing> -- set animation to <the animation you want>

    Hi Zelda, sorry to bother you again, I don't understand how to implement detect angle from the pathfinding tool. I can only see the angle from my NPC that is not related to it. Any pointers on that matter? I'm looking it up on the internet but I can't seem to find anything.

    Cheers.

  • here is a sample I was playing with last week that sets units animation based on the moving angle.

    you select units with the left mouse button, and send them to a location with the right mouse button.

    I borrowed the player unit from the Demonoire game demo...

    in another sample I am still working on I use pathfinding to choose a path for the units, but then I use MoveTo to get the units there. Pathfinding only takes units close to the destination. If you want units to got to an exact spot you have to use MoveTo, add waypoints found with pathfinding, and then set the final waypoint to the spot you want the unit to arrive at.

    https://www.rieperts.com/games/forum/SelectUnits.c3p

  • here is a sample I was playing with last week that sets units animation based on the moving angle.

    you select units with the left mouse button, and send them to a location with the right mouse button.

    I borrowed the player unit from the Demonoire game demo...

    in another sample I am still working on I use pathfinding to choose a path for the units, but then I use MoveTo to get the units there. Pathfinding only takes units close to the destination. If you want units to got to an exact spot you have to use MoveTo, add waypoints found with pathfinding, and then set the final waypoint to the spot you want the unit to arrive at.

    https://www.rieperts.com/games/forum/SelectUnits.c3p

    Thank you Allan, this has just what I needed. Through system I can call the NPCs and use the same code as Zelda posted for the angles and the animation changes, I just didn't know where to start with that.

    I see that you used a Direction state to tie the angles to the animations, now I understand it clearly.

    Thanks guys!

  • Definitely works now with pathfinding.angle, however, for some reason my animations don't play, they get stuck on the first frame, the WalkUp animation seems to work fine (I already checked, they are all looping and have working frames) but all the rest just get stuck. Similar to my Player sprites when I press diagonal directions.

    I tried with implementing states and Direction for the coding and that just leaves the NPC idling all the time. At least now they change direction and to the correct one, but no animation sadly.

  • Was able to get it right by giving the states and booleans another try, tying the animations to states doesn't make your key down constantly call the animation, leaving it stuck at the first frame.

    Thank you for all the help guys, guess I was doing animations the wrong way all this time. States are the way to go lol

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)