![]() First the bounding boxes areĬhecked to see if they overlap (it is pointless to waste CPU time on SATĬalculations unless that is the case). SAT Rectangle Collision Example for GiderosĮxample project that creates and displays 2 rotating boxes that can beĭragged about the screen by their center points, and detects collisionsĬollision detection is a 2 part process. ![]() Īnd finally this series of articles is pretty good at showing how to make a Mario style platform collision engine. Love2D is LUA based and "most" of the things you will find there are fairly easy to get working with Gideros (except HardonCollider ROFLS)Īnd here's a neat little blog about circle collision/resolution with LUA code too. In general it's a great place to go (check out their forums too) to find code and stuff. You can find a few others collision libraries at. Its hard to get working with Gideros (don't even go there) but it has some great code and there's a lot to learn from reading through it. There is also a rather cool library called HardonColider which uses SAT. This one has a simple explanation of SAT and has LUA source code too. I haven't looked at this closely but it's another library from the looks of it. If you want to go down the SAT path then here are some other links. If I had discovered bump before writing my own collision engine, I would have saved 3 weeks heheh. I twrote my own collision engine and whilst it is pretty good, it doesn't come close to bump by a long way. I still wholeheartedly recommend bump for grid based games. This tutorial provides great info on collision great explanations If you are doing something simple, complex libs could slow things down while 2-3 lines of Lua code is often faster. It is not necessarily better to use Box2D or other libraries. The point is you can write your own collision detection code right in Lua. The disadvantage of this is you need to constantly update the cell index number for each object but it means many collision tests can be avoided. In this case you can be sure A and B are not colliding as they are in different cells (and not neighbouring cells). Eg it might be quite coarse like 3x3 and A is in cell (1,2) and B is in cell (3,3). If the rectangles overlapped then you have to do the detailed calculation to see if the objects overlapped.Īnother approach is to divide the game area into a grid and assign each object to one cell in the grid. If those rectangles didn't overlap, then no collision took place and you can skip to the next pairing. But you can be sure they didn't collide if you consider the rectangle that encloses eg A and B. Eg if A, B, C, D are all strangely shaped objects (polygons) then checking a collision involves some complex mathematics for each pair. In principle there is no way to check if object A collided with any other objects (B, C, D etc) without looping over B, C, D and checking each one. I don't have much to add beyond the excellent suggestions above, but just take a step back to look at the theory of it. You can also just call reset() if you just want to clear the generated data. ![]() Subsequent calls to createRectangles() will remove any previously added collision rectangles from the bump world. Finally it adds the created rectangles to the bump collision world. NOTE that the function treats any non zero tile as solid. Each rectangle is created with a isWall bool variable to make it easy to differentiate them from other collision objects in bump. The function its-self It makes two passes over the layer, with the 1st pass creating vertical rectangles, and the 2nd pass creating horizontal rectangles. map is a loaded tiled map and name is the name of the layer you want to make rectangles from. The main function you will call is createRectangles(map, name). Subsequent calls to render() will attempt to dispose of any previously created resources.ĬollisionMaker - Creates collision rectangles from a tiled map and adds them to a bump collision world. It just draws tilemaps and in the code it has placeholder code for processing object and image layers as well. This class is based on the Desert example. If you are going to use a tilemap with Bump then maybe you will find this example project of use. My current experiment in Gideros uses Bump for collisions.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |