Navigation 2D Path finding follow Player - Far Star Game Devlog #5

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello again welcome to another dev vlog i'm vinnie and this is firestar i was supposed to release this video last month but things didn't really work out that well so today i'll talk about using navigation 2d node for bath timing in a 2d side view slash platformer game i'll show you how i've done it in firestar and what are the edge cases to think about if you heard already about the navigation 2d node it's basically a high level path finding node you will draw navigation polygon or multiple navigation polygons and it calculates the closest path between two points this works really well for top down or isometric games but when talking about platformer we have a few more challenges like gaps gravity and one-way path i've tried different approach like using title maps or godo's a-star implementation but using a navigation 2d node was the method that worked best for me ok enough talk let me show you how to use the navigation 2d node and then i talk about edge cases to consider first you need to add the navigation to denote your scene then you need to define your path aria i do that by adding navigation polygon instances and drawing them in the editor but you can also use a tile map for that or even create them programmatically after defining the aria you just need to use the navigation node in your script the main method you should care about is get simple path this will give you all the points between your starting position and your ending position then you can iterate over them until you reach the end that's pretty much what you need for top-down games but when talking about a side view slash platformer you probably will be handling gravity jumping between platforms is simple the way i solve it in farstar was adding a raycast to my character so it can sense when facing an edge and then just jump also one thing i like to do is to detect if the next step is below the character so instead of jumping they just fall from the platform that feels more natural the one-way path situation is a little bit trickier i solve this with a little bit of brute force after calculating a path i verify if all points are reachable at the moment i do that by checking if the height difference between two points is greater than the max height my character jump can reach if the main path is unreachable i calculate two alternate path of setting the start position of my character then i choose to close which one and if it still can't reach it i just give up this path not for me the main reason this works is because i recalculate my path periodically in five star most of my targets can move so i need to sync the path to the target constantly what this means is that even if i use an alternate start position most of the times my path is recalculated again before reaching this alternate position the scenario we need to handle and this is not exclusive for platformers is collision avoidance you may have a situation like a door being closed or a collider getting the way so one cool thing is that goto 4 will have a new navigation server with collision avoidance included and many other features but we don't know when it's going to be released so for now you have to implement it yourself there are a few different ways you can deal with it one is adding an exception polygon to your navigation with the shape of your collider that's a little bit tricky and as i haven't implemented myself um i won't talk about that the second option is to detect collisions and try to work around them my characters have two raycasts that check if the object in their way can be jumped the bottom raycast detects the object ahead and the top one tells the actor if the collider is short enough that can be jumped it's quite basic but it seems to be all i need so far when talking about doors you can use the multiple polygon strategy remember i said you can add many polygons to your navigation 2d well you can also disable those polygons independently so when closing the door you can disable all the path behind it or maybe just a small connector between both polygons if you prefer in five star i was experimenting with the idea of doors having their own navigation polygon so they can be disabled when the door is closed it works quite well and here's a quick tip when working with more polygons for a path to work with multiple polygons they need to have at least one vertice overlapped what this means is that you need at least two neighbor points in both polygons with the same positions to make things simple for you you may enable pixel snap in the editor so you don't face problems with points being a few decimal digits away and there you have it so i created this example so you can see in detail how all those things work you can find the source code in my github the link is in the description besides the navigation logic in this project you can also find an example of auto tiling and gravity implementation this time i decided to make a fancier example project so i picked a tile set on each io this is a popular one you've probably seen it before in other videos or examples maybe on pinterest but i want to give it a shout anyway because it's really well done it was made by pixel frog who makes some really cool pixel art so check it out if you like this video press the like button and consider subscribing if you didn't like i don't think you would be watching this far but if you are leave a comment telling me what i could have done better that's all for today thanks again see you next time you
Info
Channel: This Is Vini
Views: 2,686
Rating: undefined out of 5
Keywords:
Id: LKyGdiHzIk8
Channel Id: undefined
Length: 5min 55sec (355 seconds)
Published: Wed Dec 16 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.