Godot 3D - Floor Independent Pathfinding Part 1 - FPS Horror Project (GDScript) | 16

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome back today we're going to be creating our AI nav pathf finding and this is going to be the code that will be generating the path for the AI to actually crawl on the ceilings and stuff that being said this is going to be a very large subject so we're going to be splitting it into two parts the first part is going to be going over how to create a path that will move along the ground jump up onto the wall or the ceiling and then move along the wall or ceiling and have the chance of jumping back down and have all of that be very fluid and just work with the AI as it currently stands it's also going to be having code to handle the grounded State as we need a enum to determine whether it's on the ground in the air or on a wall or ceiling then we're also going to be working on some error handling to make sure that if the AI happens to get closer to the next Waypoint due to physics or what have you as this is a physics based AI movement then it will go ahead and just jump to the next Waypoint instead of trying to get to the current Waypoint and then we're also going to be doing a check to see if we have been trying to get to a waypoint for too long we need to go ahead and generate A New Path to try and get to the Target location to make sure that the AI doesn't get stuck too much we're going to go ahead and dive into a Blackboard real quick before we get to the code and we'll use that to kind of break down what the current objectives are and how we're going to be achieving them all right we're in the Blackboard here this is kind of where I originally started my intention was to create a 3D model that would represent all of the navigatable areas much like an autogenerated nav mesh that would be on the floor but this would actually wrap around the surface all the way up to the ceiling and all the pillars and everything this would allow navigation anywhere on any of the surfaces in the game and the way this works is you take a point a and a point B that's the origin point and the target point and the nav mesh will find the two closest points on the mesh and then navigate through the mesh in order to find the closest distance and it does this through some Wizardry on the back end that I'm not too concerned about then it creates a series of waypoints which are marked in green here now this does work but the problem wasn't actually with the nav mesh I ended up running into the problem when it came to authoring the nav mesh so this is kind of what I actually got to and what it amounts to is a sculpted out 3D model that is then shrink wrapped to the scene geometry to create a nav mesh and this was very slow to create and I realized about halfway through when I got about this much done that this was going to be pretty much impossible for me to recommend anyone to actually make besides myself and since I couldn't recommend it to anyone else to make I figured implementing it into the project really wouldn't be viable so what I decided to do was something a little bit different so first off we have our level geometry and that's in white here then we have the autogenerated nav mesh and that's in blue here and say you want to get from point A to point B the automated nav mesh just like up there will go ahead and create you a path which is a series of way points from point A to point B now these way points are highlighted in green green so my basic idea was using this path I can typically decide that there will be geometry somewhere in the ballpark of this path so every so often say about 10% of the time we'll go ahead and decide that we want to be on the ceiling or on the wall or what have you so from one of these points say we decided this right here we'll go ahead and create a raycast which will pick a random Direction upward so let's say it goes over to the right and using that it will go ahead and find the location on the wall that counts for this this will create a jump Target now what this will do is when the AI is coming along instead of continuing on to this node it will now jump towards this node and attach to the wall and then because of this Ray cast being successful and US knowing that there is a wall up into the right of this we'll go ahead and reuse the same Ray further on for every node as we progress now there may come a time when that node will be incorrect or simply too far away from the wall at which point we will decide we now need to go ahead and move back down to the ground and at this point the AI will go ahead and jump down this creates a new path that allows the AI to run jump up onto the wall run along the wall and then jump back down now in practice this actually looks pretty good the movements are fairly organic and this allows the AI to pretty much interact with any environment the only downsides being that it really doesn't work well with extremely tall rooms so if you have a room like the entrance up here the AI aren't really going to run all the way up the entrance because generally they're trying to get from there location to your location and that doesn't really necessitate going up the entrance further now there are a couple issues with this say for example you have a second path that instead of going in between the pillar and the wall goes outside the pillar and say you're already running up the wall which means that these rays are cast every so often and the ai's current position is actually on the wall running along now this Ray right here would actually impact the pillar and thus the AI would believe that it should run along the wall and then run all the way over here and then run all the way back to the next point and obviously this is incorrect this is impossible so a couple there's a couple safeguards that I ended up taking to resolve this first off anytime it is rayc casting along like this if the raycast point is more than about 25% greater or less than the original raycast point then it will go ahead and just break out and go back to the walking position this will allow the AI to kind of handle any pillar it just kind of snap snaps out of running on the wall when there's a pillar between it and its original path now this does result in them coming off the walls fairly frequently if there's a lot of pillars in the environment but it also doesn't look half bad so it gets the job done now besides that we also have a slight issue with overshot so due to the way we're actually jumping up onto the wall it's very conceivable that we may end up actually farther down the path than we had originally intended so I do a little bit of math to resolve this if the ai's actual position is closer to the next wayp Point than it was to to the previous Waypoint we just go ahead and erase the previous Waypoint and go on to the next Waypoint and that's pretty much it the end result is now we can have ai run along run along the ceiling run along the walls and jump back down and interact with each other in a fairly fluid and natural way now that being said the path generation and the actual navigation of the path were going to be breaking up into two separate videos as they are fairly complex subjects and I don't really think I could get a single video with all of it without it being excessively long so we'll have this NE this week and then next week we'll actually go over how to make the AI move along it that being said let's go ahead and dive in and get started all right so hopefully you have a bit of an understanding of what we're going to be doing today so we're going to go ahead and dive straight into code now there's a bunch of functions that we need to do before we can rewrite this physics process as the physics process is going to kind of iterate through the path and then once we've reached a Target destination we'll go ahead and be killing that path but in order to do that we need functions to handle the creation of paths the destruction of paths and and the stepping through of paths so first off we're going to be starting off with exports then we're going to be doing all the functions then we're going to be coming back to the physics process and going ahead and wrapping it up there let's go ahead and get started first off we're going to be creating a new class and if you're from C this is going to basically be like a struct and c and we're just going to be passing in the Waypoint position normal and then a Boolean setting whether we're on the floor or not and an estimated Waypoint duration this is just going to be used to do error control to make sure that if we get stuck we go ahead and repath if we been trying to get to a waypoint for too long now I didn't realize this when I first started this project but you can actually create little sub classes like this and then use them in the script like Str in C and we're going to be using this pretty extensively going forward so we're going to be starting with this this will be our little pathway Point object now below that we're going to need a signal and the signal is just going to be launch request this will be used anytime we need to launch from the floor towards the ceiling or vice versa and it's going to be kind of different than a normal jump as the jumps are just used to move around the environment whereas launches is used to actually transition from One path state to another and that signal will just be listened to on the limb controller in order to jolt the AI from the floor to the ceiling or what have you now next up we're going to go ahead and create two export groups the first one is going to be path navigation that is actually going to be used for the velocity and things like that we're not going to use that navigation agent though and the second one is going to be for path generation now the path generation is going to have a lot of export variables but the path navigation is going to have just the maximum velocity as well as the velocity change and another float for the minimum launch delay we're just going to use this to make sure we don't spam the launch request and we don't end up bouncing around the environment really fast I'm going to go ahead and delete that physics process as we won't be needing it just yet and down here in the second export group for the path generation we're going to create a fair few variables the first one is going to be the debug active variable that's just going to be used to draw a line wherever the AI is going and it's going to be defaulted defaults but later on this will be invaluable to determine if the paths that we're generating are actually ideal then we're also going to have a ground check distance which is just going to be used for the grounding code as well as the stopping distance which is the distance that we use to stop before we get to a waypoint this is going to be exactly like navigation agent 3D next up we're going to have something called a wall roof distance change allowance this just going to be a percentage from 0 to 1 representing 0 to 100% And it's going to be the distance from the origin of the path on the wall to whatever the distance from our Waypoint currently is this is a little bit hard to explain but I explained it in the Whiteboard basically all this means is that if we vary too much from our distance that we're stepping up to get onto the wall then we'll go ahead and just snap out of climbing on the wall and go back to the floor based pathfinding next up we're going to have an up path check distance this is just going to be the distance from the Waypoint that we're willing to check for an environmental path if you do this too crazy then you might end up never actually being able to reach certain parts of the ceiling or what have you with the jump velocity and you may need to work on the jump velocity and then we're going to have a world Collision Matrix and this is just going to be using the export Flags 3D physics and we're going to be passing it an in which is World Collision you can see over here we already have that and if you select over here you can just select world and that works out just fine and last but not least we're going to have a chance of up path this is between zero and one representing zero and 100% chance and the chance I tend to set around 10% or 0.1 and you can set this to whatever you like if you set this too high though the AI will never come off the ceiling and it just looks kind of funny you end up with a empty ground below you and a whole bunch of AI all over the ceiling there's a couple private variables the first one going to be the desired velocity then we're going to have a Target position that's just going to be wherever we're currently pathing to as well as a last retrieve pathway point which is of type pathway point and this one's going to be used anytime we want to get our current desired location following this we're going to go ahead and create a grounded State enum instead of just using a Boolean to say whether we're on the ground or not we actually have to use an enum because since we can be on the wall we need to determine whether we're on the wall on the floor or in the air speaking of which we're going to go ahead and have a current grounded state which we're just going to default a grounded state state. nun and we're also going to have a current ground normal now we do have a normal that's just the last retrieved pathway Point normal so that's whatever the desired normal of the pathway point is so if we're on the ground it's just going to be Vector 3. up but then we also have a current ground normal and every time we check for the grounded State we're going to be getting the normal based off of that and so if we happen to be running on the wall we're going to have this be the actual proper truth of what the normal of the wall is as opposed to what the desired waypoints normal is and this is just necessary for some basic code for making the Torso rotate properly to the wall that it's climbing on next up we're going to have initial wall roof distance this is going to be up type float and it's just going to be defaulted to zero this is going to be used with the wall roof distance change allowance in order to determine if we should snap off of the wall or not next up we're going to need a couple timers the first one's going to be launch attempted interval and that's just going to be used with the minimum launch delay to make sure we don't spam launches then we're also going to have the Waypoint failure timer which is just going to be used with that estimated Waypoint duration up there to to make sure we aren't stuck just below that we're also going to have the internal gravity scale this is going to be whatever our current gravity scale at this launch of the game is we're just going to set it to the gravity scale we're going to use this to reset the gravity anytime we're on the ground or in the air and then we're going to be setting it to zero when we're actually on the ceiling so that that way we don't immediately fall off the ceiling then there's a couple variables here that are a little bit different we're going to have to have a RNG or a random number generator and we're going to be using this throughout the entire process for any sort of determination that needs be random so we just cach it here so we don't create a bunch of extra memory we're also going to have a current path which is going to be an array of pathway points we're going to be removing the first one in line each time we get to it using the stopping distance float up here but the current path will ideally always have something in it as it will be navigating around and then anytime it's just standing still the current path count will be zero then we also have a rid of the nav map now this one's a little bit weird this uses the rid which is kind of a pointer to a location in memory or an object in memory and the nav map is going to be pulled from the 3D world that the AI is in upon start now the nav map is actually this blue mesh here and it's used for the navigation it's kind of autogenerated in editor using goodto tools and we're going to be accessing that via nav map so that we can kind of create our own paths without use of a navigation agent 3D now that we have all of that out of the way we can go ahead and create our ready function and there's a couple things we need to get done first we're going to be getting the nav map from using the function gworld 3d. navigation map that's just going to return any navigation map in the world then we're also going to be setting our internal gravity scale to the current gravity scale which is just that value right there and last but not least we're just going to go ahead and randomize our RNG and create a new random F range between zero and minimum launch delay and assign our launch attempt interval to that value this is just going to make sure that whenever the AI all spawn we don't have them all immediately jumping at the exact same interval or otherwise it just looks kind of funny now next up we're going to get into all the functions we're going to be starting with the set Target function this is going to be passing in a vector 3 which is going to be our new Target and first off we're going to go ahead and clear our current path and randomize our RNG then we're going to be creating A New Path which is just going to be an array of vector 3 pulled from the navigation server 3d. mapg path function and we're going to be passing in that nav map that we went ahead and assigned as well as our Global position and our Target position as this function requires an origin and a destination then we're also going to be passing it in FAL as the optimized path Boolean and this is just going to make sure that the path is not optimized it has regular way points at a very high density the reason for this is we want the density to be nice and organic and it as it moves through the environment if you set this to true you will actually get much better optimization now we're going to create a couple variables that are going to be used throughout this path generation function and these are going to be the current up Vector the last Waypoint the last on ceiling which is a Boolean and the current path chance which is a float so the current up Vector is just going to be whatever the normal is so that's going to start out by Vector 3. up and then we're just going to assign it based off of the the environment as we move through it then the last Waypoint is going to be whatever the last Waypoint is which starts out as the global position but as we iterate through this path it will be set to whatever the previous one was as well as laston ceiling which we're going to default defaults but here in a second we're going to assign that and then we also have the current path chance which is going to be the chance of up path divided by the New Path do size as I want the chance of up path to be based off of the entire path so it'll be 10% of all paths not 10% of all way points which are two very different values now next up we can go ahead and check to see if our last retriev with path Waypoint that means we have been moving through a path already we're just going to set our last on ceiling to whatever the current Waypoint knot on floor value is and this means that if we are currently on the ceiling and we're repath we're going to start out on the ceiling that way we don't create a lot of noise in jumping up and down all the time and before we get started on the new path for loop we're going to go ahead and create a new space state which is just going to be using the function get World 3d. Direct space State this is going to be how we interact with the environment using raycast and things like that now we can go ahead and create a for Loop now we're going to iterate through all of the New Path and we're going to call each one the Waypoint and then we're going to be assigning these to the current path array as New Path waypoints so let's go ahead and get started with that first off we need an estimated duration so we're just going to use the distance from the last Waypoint to the current Waypoint divided by maximum velocity and we're going to check to see if we are currently on the ceiling and there is a random chance of the current path chance multiplied by two that means we are currently on the ceiling and we've decided that we would like to try and not be on the ceiling so we're going to set last on ceiling to false now what this means is that if we currently if our current path chance is 10% then 20% of the time if we're on the ceiling we will try to come off of the ceiling now this doesn't mean that we necessarily immediately come off the ceiling it just means we have the chance of coming off the ceiling now inside here I am going to create a new if statement that just says if debug is active let's build a debug line from the last Waypoint to the current Waypoint and we're going to set it time timer to two and its color to Blue and all this is going to mean is that if we are coming off the ceiling let's go ahead and create a line that just marks us coming off the ceiling so we can use it as reference during debugging and now we can go ahead and set our last Waypoint to the current Waypoint as we've pretty much gotten everything we needed from the last way point now we're going to go ahead and create a new pathway Point here and we're going to be using the pathway point. new function but we can't really create Constructors in gdos script so we're just going to have to assign all the variables right out the gate so we created a new Waypoint then we set it Waypoint normal to Vector 3. up that's just the default and its Waypoint position to the current Waypoint as well as its Waypoint not on floor to fault that means it is on the floor and it's estimated Waypoint duration just to estimate duration now we can go and say if we're not currently on the ceiling we're going to check if a random F which just means between zero and one is less than the current path chance this is why I said just because you set it to last on ceiling equals false does not mean it immediately jumps off the ceiling because there is a random chance that it'll just decide to be on the ceiling anyways and it'll go ahead and create a new up Vector which is used for for the raycast to determine where on the ceiling we currently are pathing to now the for the current up Vector we're just going to use Vector 3.1 plus Vector 3.1 multipli brand F range minus 0.5 multipli 2 all this is going to do is get a vector 3 that's anywhere from negative 1 to positive 1 in any direction plus Vector 3.1 which means that it'll always generally be above the current position and we're going to use that as a normal for the raycast and that'll just get a random Direction somewhere up now if that random value is not equal to to true now if that random value is not equal to True which means we are not currently wanting to do this we aren't currently wanting to be on the ceiling then all we have to do is go ahead and add this to the current path and use the continue keyword which is just going to go to the next for Loop so it'll just mean no I'm not on the ceiling and I don't want to be on the ceiling I'm just going to add this Waypoint as it currently stands with its Waypoint position equal to the current Baseline Waypoint returned from the navigation system and I'm just going to continue on to the next Waypoint now if we get past that it does mean that we want to be be on the ceiling so in order to get that we're going to go ahead and create a new Ray cast and this is just going to be using the physics Ray query parameters 3d. create function we're going to be passing it in our Waypoint as the origin and we're going to be passing it in our Waypoint plus the current up Vector multiplied by the up path check distance which is just going to get us a position somewhere above the current wave point in a random position and we're going to use the world Collision as the Collision Matrix and just use the space state. intersect Ray with the query as the parameter and that's going to return result now in Theos script all you have to do is say if result then that means we have Ray casted against something we can go ahead and create a couple new variables here for the current distance which is just the result. position's distance to the Waypoint and the current change Delta which is the absolute value of the current distance minus the initial wall roof distance divided by the initial wall roof distance now all this means is that that Delta is going to be between 0 and 1 or greater than one and the higher the value then that means that the more different from the Baseline it is so if our wall roof distance change allowance is 0.25 then that means that if this value is greater than 0.25 it means it is more than 25% different than the Baseline then we are too far separated and we need to go ahead and snap out of it so if that is the case we can go ahead and just set the last on ceiling equals TOA and that's all we have to do to make it no longer be on the ceiling as we have already created a new Waypoint up here to be used that is not on the ceiling however if that is not the case then we do want to be on the ceiling and we have Ray cast against the ceiling first off all we're going to do is if we're not currently on the ceiling then we're going to go ahead and set our initial wall resistance as this is the first time we've breasted against the ceiling and we're going to set last on ceiling equal to True next up we need to set up our new Waypoint to actually be representative of the ceiling position so we're going to set its Waypoint position to the result. position and its Waypoint normal to the result. normal we're also going to set it Waypoint not on floor Boolean to equal to True either way whatever the result of the raycast is we go ahead and add it to our current path and that's pretty much it for this for Loop now we do need to do a couple other things before we can actually call this current path valid and that's just going to be to check to see if the current path size is greater than zero and if so we're going to set the target position to the last Waypoint position so that that way we know when we've reached the target position and we can also use that in order to recreate the path if in the future we get stuck we can just call this function with the target path as the new Target and if it's not the case we can go ahe and set the target position equal to the global position and last last but not least for debugging sake we're going to go ahead and create an if statement that says if debug active then we go ahead and create a new variable which is just going to be our Global position and we go ahead and iterate through all of the waypoints and create a line from the last Waypoint to this Waypoint with the color of just red and a duration of 5 Seconds then we go Ahad and set our last position to this position that just means we iterate through all of the waypoints and create a line that is just the path that the AI is going to follow down and that's pretty much it for the set Target function now there's more functions that we need to go ahead and create so first off we're going to be creating the is Target reach and that's just going to return of type Boolean and all it's going to return is if the current path size equals to zero so that just means we no longer have a path that means our Target is reached we can also go ahead and create a couple functions for the normal so we can get our current normal and our get ground normal and our ground normal is just going to be the current ground normal which is going to be generated using the grounding function but then the current normal is going to be using the get next Waypoint function so let's go ahead and create that as it doesn't currently exist so first off in the get next way Point function we're just going to check to see if the current path size is greater than zero that means we do have a path and our last retrieved pathway Point does not equal the first element in the current path that means that we have changed the current path's first element which means we have iterated through the waypoints then we need to go ahead and update the last retrieved Waypoint we're going to set the last retrieved Waypoint path to the current path zero and that's just going to be the first element in the current path and we're going to set the Waypoint failure timer equal to the estimated Waypoint duration now the reason why we go ahead and set this here is because we want to make sure that no matter what we only call this Waypoint failure timer update once so that that way we don't end up keep resetting it I actually found that to be an issue in the earlier attempts of this and we can go ahead and return the last retrieved Waypoint path now there is one other thing if we haven't currently got a path and our last retrieved Waypoint path is equal to null that means that this get next Waypoint function has been called but we've never actually been on a path so we've never generated that first last retrieved path Waypoint then we need to go ahead and create basically a standin it's just going to be our Global position with the vector 3 normal of up and our Waypoint Waypoint KN on floor equal to fault this way no matter what this function will return something so that that way we never get any null reference exceptions now speaking of which we do need a function to determine if we have reached the next Waypoint path so let's just create a new function called Waypoint reached check and this is not going to return anything it's just going to be checking to see if we have reached the next Waypoint first off we're just going to check to see if the current path size is greater than zero if not we're not going to do anything and we're going to check check a couple things we're going to create a new Delta which is just going to be the difference between the current Global position and the Waypoint position of the first element in current path and that's just going to be a vector pointed at the Waypoint position from the global position and we're going to create a new Boolean that says closer to next equals false and launch equals false we're going to both of these will make sense in a second then we're going to check to see if the current path size is greater than one this means there is more than one Waypoint in the path that means we aren't right at the end yet we do have another path way point position to go to after this next one we're going to set our two booleans now our two booleans are just kind of used to determine what functionality we need to actually use so the closer to next just checks to see if the distance between our current Waypoint position and our Global position is greater than the next Waypoint position and our Global position so if closer to next is true that means we are closer to the next Waypoint than we are to the current Waypoint the reason why I go ahead and check this is just in case we overshoot due to physics because of the way our AI works with physics we want to go ahead and just set it to the next Waypoint in line instead of trying to backtrack then we also have a Boolean to determine if we should launch now if we should launch is determined based off of if our current path size is greater than one and our next Waypoint does not equal the current way points on floor value so that means we're on the ceiling going to the floor in the next Waypoint or we're on the floor going to the ceiling in the next Waypoint finally we go ahead and check to see if our current Delta's length is less than equal to stopping distance or we are closer to the next value value then we need to go ahead and update our current path so we'll just set the current path remove at zero function that will go ahead and remove the next Waypoint and if we do have a launch command then we need to go ahead and set our launch attempt interval to the minimum launch delay which will be subtracted in the physics process and we go ahead and emit the signal for launch request this should go ahead and launch us onto the ceiling and if it fails then the physics process will just go ahead and keep reattempting until it succeeds now last but not least we do need to go ahead and create the get grounded function now get grounded is going to return a grounded State enum and it's going to be a fairly complex function now under normal circumstances you just do a ray cast downwards but that's not really going to work out for us first we need to go ahead and do a sphere cast to see if we're near any walls whatsoever so for that we can go ahead and create a new physics shape query parameter 3D and we can go ahead and create a new sphere shape to go inside of that that's just going to be of type sphere shape 3D and its radius is going to be the ground check distance we can just go ahead and assign that to the sphere query. shape variable and then we can also go sign our transform to the global transform so that's just wherever the AI currently is and our Collision mask to the world Collision next up we can go ahead and get our space State just like we did for the other function and we can go ahead and assign our default current ground normal to Vector 3. up just so that if anything doesn't collide with it we go ahead and default to our ground normal being up then we go ahead and create our intersect shape function and return the result now if we have a result we're going to be returning a bit more of a complex function but if we don't we can go ahead and return grounded state. none as We Know no longer are on the ground we're not near anything using the sphere query so we can go ahead and just default To None now if we have got a result then we go ahead and get our normal this is going to be using the get current normal function that'll be using the get next Waypoint do Waypoint normal which will just be whatever the normal should be so if we're on the ground that's just going to be up but if we're currently crawling on a wall then that should be some different angle pointed generally downwards so if it is Vector 3 do up then we know we should be on the floor so we're not going to worry about anything else we're just going to return grounded state do floor that way if we happen to be on the wall slightly but we are supposed to be on the floor you should just go ahead and apply physics normally as if we're on the floor and that should pull us right off the wall now following that we can go ahead and create a new raycast query which we're just going to be using the physics Ray query parameter 3d. create function just like we did before we're going to be passing it our Global position and then we're going to be passing it for the Target position a global position minus the current normal so if we're on the wall remember that it's pointed down into the left or down to the right or what have you by subtracting it we're going to create a Vector towards the wall from our current location multiply by the grounded check distance and then we're just going to be using the world Collision Matrix as the Collision Matrix and then we get the ray cast result using the intersect Ray function now if that equals true then that means that we are near the wall that we're supposed to be near in which case we're going to go ahead and set our current ground normal to the raycast result. normal so that's whatever the wall nearest to us is and we're going to be returning the grounded state. wall roof value for the grounded State Eno if that's not the case then we're going to go ahead and return grounded a.4 and that's pretty much it for the get grounded function now we do have one more function remaining and that's going to be our physics process now we have all of the helper functions so we should be able to Breeze right through the physics process pretty easy first we're going to check to see if our Waypoint reach check and then we're also going to be going ahead and getting our ground state we don't want to ever not get an updated grounded State as this is used for other things other than just pathfinding next up we're going to check to see if our Target is reached then we need to set our desired velocity equal to Vector 3.0 and go ahead and return however if that's not the case it means we we do have another Waypoint to go to so let's go ahead and get that we'll use the get next Waypoint function to create a new Waypoint and first off we can go and check to see if our current grounded state that we got up here equals grounded state. nun that means we're in the air we need to go ahead and default our launch attempt interval to the minimum launch delay this just means if you're in the air and you land you don't immediately bounce back up you give it a little bit of time for the AI to settle and like reposition however if that's not the case and launch attempt interval is greater than zero let's go ahead and subtract Delta from it next up we we go and check to see if our current Waypoint is not on the floor so that means we are wanting to be on the ceiling and our current grounded State equals the ceiling or wall we can go ahead and set our gravity scale equal to zero this means we are on the wall or ceiling that we want to be on and we can go ahead and set our linear velocity minus equals the current ground normal multiplied by 0.5 all this does is add a tiny little bit of a nudge towards the wall constantly to kind of stick the AI to the wall or ceiling and it's little enough that you can kind of just knock them off using physics or they can knock themselves off pretty easily probably ought to set this as an actual parameter that you can modify in the inspector but for the time being this works just fine now if this is not the case that means we are not currently on the wall of the roof we need to go ahead and try and get on the wall or roof because our Waypoint is telling us that we need to be on the wall of roof so we go and check to see if our current grounded State equals floor and the launch attempt interval is less than equal to zero that means we're on the floor and we've been there a little while we can go ahead and set our launch attempt interval back to the minimum launch delay and go ahead and request another launch function and regardless of the case if we're on the floor or in the air we need to go ahead and set the gravity scale to the internal gravity scale that way we fall normally and if our Waypoint says that we're not supposed to be on a wall or ceiling anyways we need to just go ahead and default our gravity scale to the internal gravity scale now besides that we can go and set our desired velocity equal to the current Waypoint position minus the global position normalized multiplied by maximum veloc this is almost identical to the way it was before and last but not least we can go ahead and check to see if we are debug active let's go ahead and build a line pointed towards our next Waypoint position with the color of green and this will just be helpful for debugging where the AI is trying to go and that's pretty much it looks like this code is pretty good to go next week we're going to be jumping back in with the AI controller in order to make them actually move along this code as well as the limb controller to help with the launching and help with the foot positioning but that's it for today thank you all for watching as always I know it's been a little bit of a longer video I hope that this has been a little bit more digestible though and we'll see you all back here next week for part two of this tutorial
Info
Channel: Bonkahe
Views: 452
Rating: undefined out of 5
Keywords:
Id: lkoI8JFYA2k
Channel Id: undefined
Length: 31min 30sec (1890 seconds)
Published: Thu Jan 25 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.