Waypoints in Unity - Love 'em or Hate 'em?

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
this will be a quick video on waypoints i've been intending to make a video every week but it's been about a month since my last video i've been busy working on some things that can be topics for multiple videos so i will try to get these made more regularly going forward in my last several videos i showed the details of how to create an animated human character in unity and have that character navigate to a destination through an environment such as the city scene the destination was set just by clicking somewhere the next step is to have some pre-existing destination points so that the character can patrol around as though the non-player character is on some sort of mission or to just wander between the points if all we want is for the npc to look busy in the background i mentioned in the last video that i have mixed feelings about the whole waypoint approach because it seems kind of counter to the idea that we have an artificially intelligent character doing something interesting the waypoint approach seems a bit mechanical nevertheless waypoints are commonly used so let's talk about them at least as a stepping stone and sometimes waypoints may be a means to an end when we use a gps while driving or walking we are essentially giving ourselves way points but towards the higher level goal of reaching the destination and what we will do when we get there a waypoint can be no more than a destination so it can even be an empty game object having only its transform which includes its position there are a couple of things to consider when an npc reaches a waypoint how does it choose the next waypoint also how do we place the waypoints in the scene to begin with as the most simple approach to the first question the unity manual gives an example where the waypoints are held in an array when a waypoint is reached the next waypoint becomes the next destination that may be okay for a small number of npcs if their goal is simply to reach a final destination but for a crowd of npcs i would not recommend it this video is from the simple pedestrian system from the asset store it works this way and just looks like a line of automatons following what is obviously a single path back in 2017 i released an asset called the npc populator which implements a lot of what the series of videos have covered so far and more i'm working on an update to the npc populator that will have some new features that will hopefully be available within a few weeks here's the approach i took to selecting the next waypoint in the npc populator first choose a random waypoint that is in front of the npc and within some distance threshold if there aren't any that fit the first criteria choose a random waypoint that is behind the npc but still within that distance threshold and if there still aren't any waypoints choose a random waypoint that is further away with this simple approach the wandering at least appears random and there aren't many abrupt changes in direction this is just a heuristic and could certainly be changed by modifying the code for example it might be good to occasionally choose a more distant waypoint or if there is an ultimate destination as part of a larger goal waypoints could be chosen to get successively closer to that destination now let's talk about the other question of how waypoints are placed in the scene in the npc populator i took the approach for better or worse that waypoints are game objects in unity just like any other game objects and that the unity editor provides perfectly good ways to create them duplicate them and move them around so i did not provide any tools to help with this beyond the unity editor itself i do provide a waypoint prefab which does no more than draw a couple of gizmos so that the waypoint is visible in the scene view some tool kits like the simple waypoint system shown here provide a nice point and quick tool for placing waypoints this is a nice idea and the simple waypoint system is a nice asset by the way although i've been wondering if we can go even further this series of videos is focused on ai can we develop a tool that will just automatically place the waypoints more or less where a person would i've thought about how i decide where to put the waypoints in a city scene like this i would probably put waypoints at the intersections because those seem like natural intermediate destinations and the nav mesh system can navigate then between those points that leads to the question of when i will get the city how do i recognize the intersections what do you think how do you know that this is an intersection and this is not i've come up with an approach and prototyped a waypoint assistant tool that recommends the placement of waypoints based on a few adjustable parameters the tool works pretty well for city environments it wasn't intended for wide open spaces like deserts or beaches so it doesn't work so well for those i'm going to make another video specifically about this waypoint assistant tool the ideas that went into it and how the tool is used so here again is the city example with a bunch of non-player characters moving through the city this example uses everything covered in the previous videos and also my new waypoint assistant tool what is each non-player character actually doing as we explained in this and the prior videos in the series each npc chooses a waypoint as its next destination uses unity's nav mesh system to plan a path to the destination and that path automatically avoids static obstacles like you know trees and things that might be in the way as well as dynamically moving obstacles like other npcs or possibly cars or things like that next each npc traverses that path while using the mechanim animation system with lifelike animations and only minimal foot sliding and then when reaching one way point it chooses the next waypoint so back to the topic of waypoints can we do without waypoints entirely and have the npc use ai to choose its own next destination the waypoint assistant tool that i showed briefly may be a step in that direction rather than placing the waypoints in the environment statically at the start each npc could use a similar algorithm to dynamically choose just its next destination in the next video i will show in detail how the waypoint assistant tool works i plan to include the waypoint assistant tool in the new release of my npc populator so you will be able to try it if you are interested i should mention that my mpc populator asset is not free it's not very expensive either beyond that we are finally getting to the point where having all of this as a starting point we can add more ai so that the human characters sense their environment react to what is sensed have higher level goals and work to achieve those goals for example by dynamically setting their own destinations instead of having just static waypoints so we are coming to the end of these introductory videos and what comes next will be more interesting in some cases there are well-known approaches to achieving these things in other cases some new invention will be needed figuring this all out will be fun please do let me know what you think of these videos and like and subscribe if you would like to continue on this journey [Music] you
Info
Channel: Clockworks Games
Views: 1,104
Rating: undefined out of 5
Keywords: Waypoints, Unity, unity3d, game development, unity tutorial 3d, unity ai, gamedev, unity 3d, unity tutorial, ai and games, unity npc, npc unity, game dev, indie game dev, unity tutorials, unity game development, npc, artificial intelligence, ai, game development unity, learn unity
Id: owrnfcNzb6w
Channel Id: undefined
Length: 10min 35sec (635 seconds)
Published: Sun Mar 21 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.