The MOST UNDERRATED Godot tool (GEOMETRY CLASS)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys in my latest video i showed you how to make a destructible terrain using the geometric class and today i want to take a deeper look at this awesome class quick note i'll focus only on 2d operations now but you should know that the geometry class also has some nice 3d features so without further ado let's get started the first thing i want to talk about is boolean operations on polygons i used it in my previous video to make the difference between two polygons but you can also do intersection union and zore as you can see i made a small demo with all the operations and also some other features i'll talk about them later to use these operations it's pretty simple for each of them you provide a polygon a and b and the result is given in an array even if there's only one result depending on the operation you might have more than one result for example if you want to make the difference between two polygons with one inside the other you'll have two results one will be the outer polygon and the other will be the whole you can check the nature of the polygon by using is polygon clockwise if the result is true you know it's the whole and with that you can do all sorts of operations on polygons and use the result for both polygon 2d and collision polygon you have to make sure you take into account the offset of your polygon though as i pointed out in my previous video the function takes only the polygon points and thus it will not take into account your notes transformed by default so you have to do it yourself in my latest video i asked if someone had a better solution and alfonso commented and gave a quick way to do it using poly.globaltransform.xform poly.polygon he explained that x form takes a variant as an argument which can be a pool vector 2 array which is the data type used for polygons and with that we have a nice one-liner solution thanks alphonso in my example you can see that i'm not offsetting the polygon's value this is because both of my polygons have the same location the second thing i want to talk about is the ability to check if a point is inside something we have three functions available is inside polygon is inside circle and point is inside triangle those are very similar and you probably could use the first one for everything but they exist for your convenience and the data you have available i show these three in my demo for the first one you simply provide the points and the polygons data for the second one you use the circle position and radius instead of the polygon and finally for the triangle you must pass the three points defining your triangle each function will return you a boolean telling you if the point is inside or not you have to make sure the point is matching the transform of the polygon circle or triangle so for example with is point in polygon and point is inside triangle i converted the global position of the point to the target local position so the polygon called shape a and the triangle called shape triangle for the circle i use both global position for the point and the circle center these functions are really useful for some specific use case a good example is checking if a character is inside a collision shape without using an area for example in my case i used it in my latest video when making the destructible terrain in the projectile path visualization each step along the path creation i'm checking if the point i just calculated is inside the turing polygon if it's the case i know i should stop drawing the trajectory because i hit the terrain one last example before moving on to the next functions during my 12 prototypes challenge i made a little game called snake you have to encircle foot to get it to check if the foot was inside i created a collision polygon using the line to the points i created and check the presence using the area signal as you can see it creates a micro starter with the creation taking from 11 000 microseconds to more than 270 thousands in contrast if i create a polygon 2d using the line 2d points and check the presence of all foods using is point in polygon it doesn't take more than 468 microseconds to check which is much much faster the third thing the geometric class can do is tell you where the closest point on a segment is whether it's from a point or another segment let me demonstrate how it works first and then i tell you how it can be useful in some games the first function get closest point to segment 2d text the position of your point and two points defining a segment in this case i'm using the two points of a line 2d i used to visualize the segment the second function get closest points between segments 2d will take four parameters which corresponds to the four points defining the two segments this returns an array with two points one for each segment again make sure they have the same base when comparing position for the first one i'm using the local position because they have the same origin you could use the global position instead to take into account any transformation in the second function you can see i'm transforming every point to global because i want to take into account the transform of the second segment which is moving note that there is another version of this function which uses the differential of a line instead of a segment so you provide a position and a direction a line is infinite whereas a segment is defined by two points these functions might seem very specific and they are in fact but i think you can find more uses than you might initially think of for example in a 2d skate game you might want to grind on a rail and with this function you can get the closest point to the rail and attach to it correctly the fourth thing the geometry class can do is give you the intersection point from segment to segment or from segment to a circle to use segment intersect segment 2d you simply provide the four point defining the two segments just like we did previously this gives you a resulting point but be careful because it can be known if the two segments are not intersecting for segment intersect circle you provide two points for the segment and the position and radius of the circle note that there's no function to intersect with a polygon but you can emulate that by taking each pair of points inside the polygon and use the segment intersect segment to the function and to finish this video i'll talk about two last functions that don't really fit in any category the first one is offset polygon 2d this is useful to change the size of your polygon without using the scale using the scale won't change the points and thus you'll have to offset them manually before doing any calculations and finally the last function is called triangulate dna 2d you simply provide a polygon and the function gives you back an array of points every three points defined a triangle it can be really useful to create destructible stuff in 2d i think i saw an add-on that was using that to create the pieces when a sprite was destroyed that for all sorts of things it's a very versatile function and guys that's the end of the video i hope you liked it i think this class is totally underrated and can be useful for so many things especially if you're trying to tinker a bit with godot i only covered the 2d aspect of the class so if you want me to cover 3d please let me know in the comments below as always you can find older sources in the description and even try the little demo i showed you on screen on itch if you want to support me you can wish list dashboard the local multiplayer game i'm currently working on if you want more you can follow me on twitter instagram and join the discord i'll see you soon and in the meantime have a great day bye
Info
Channel: MrEliptik
Views: 2,771
Rating: undefined out of 5
Keywords: godot, godot-engine, godot engine, gamedev, games, development, game development
Id: mRixyMUr5VM
Channel Id: undefined
Length: 7min 47sec (467 seconds)
Published: Wed Oct 13 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.