![game maker studio collision game maker studio collision](https://bs-uploads.toptal.io/blackfish-uploads/components/seo/content/og_image_file/og_image/777076/0907_VideoGamePhysicsTutorial_Razvan_Social-9c31fc66d3dfd0ef0608ee5adfcd6414.png)
- #Game maker studio collision software#
- #Game maker studio collision code#
- #Game maker studio collision download#
- #Game maker studio collision free#
GameMaker is software designed to make developing games easy and fun. The Essential Gamemaker Functions, Concepts, and Tools Guide.GameMaker Handbook - The Ultimate Resource for Beginners.
#Game maker studio collision free#
Let me know what you think and feel free to share. I have not tested all possible cases (and bugs happen). If you find any error in the code, please let me know. I’ve added a check to avoid having my player stick to the down slopes when jumping upwards (personal preference).
#Game maker studio collision download#
You can also download the project from this link: CollisionsTest.gmzĪs you can see I kept the slopes functionality. While (!collision_rectangle(bbox_left, bbox_top + ydir, bbox_right, bbox_bottom + ydir, obj_collision_par, true, false)) If there's a collision, move to contact Var coll = collision_rectangle(bbox_left, bbox_top + vyNew, bbox_right, bbox_bottom, obj_collision_par, true, false) Var coll = collision_rectangle(bbox_left, bbox_top, bbox_right, bbox_bottom + vyNew, obj_collision_par, true, false) If (yVel >= 0) & !collision_rectangle(bbox_left + xdir, bbox_top + 1, bbox_right + xdir, bbox_bottom + 1, obj_collision_par, true, true) & collision_rectangle(bbox_left + xdir, bbox_top + 2, bbox_right + xdir, bbox_bottom + 2, obj_collision_par, true, true) If !collision_rectangle(bbox_left + xdir, bbox_top - 1, bbox_right + xdir, bbox_bottom - 1, obj_collision_par, true, true) If collision_rectangle(bbox_left + xdir, bbox_top, bbox_right + xdir, bbox_bottom, obj_collision_par, true, true)
#Game maker studio collision code#
Nikles optimized collision code ///scr_collision_nick() You’ll see I simply nested the collisions because it’s useless to make the same exact collision check twice. The horizontal part must retain the repeat logic for the slopes to work correctly.
![game maker studio collision game maker studio collision](https://gamemakerhow.com/assets/tilemaps.png)
This way, in the case of a clear path, we saved a lot of collision checks. If no collision happens, we move by 10px in one go. In case of a collision, let’s just move to contact and set the speed to 0. So we either stretch it 10px to the top in case we’re going up, or 10px to the bottom if we’re going down. How do we do that? We use a collision_rectangle but we expand this rectangle to take into account our current vertical speed. We can simply check if the path is clear. Do we really need to check 10 times if we’re hitting something, and if not, move 1px each time? No we don’t. Let’s say we’re going at a vertical speed of 10pps (Pixel Per Step, I made up that word). This trick is actually borrowed from the twitter user adapted his original code to prevent going through walls even at very high speeds. What if we simply call it once for vertical and horizontal speeds and then reuse the vars (that I called xdir and ydir)? Let go of the vertical repeat Inside the collision functions there is a lot of repetition for this very simple function.
![game maker studio collision game maker studio collision](https://nikles.it/wp-content/uploads/2018/11/2018-11-12-21_08_12-Window.png)
For example – sign(458) will return 1, sign(-5) will return -1 and sign(0) will return 0. This function returns whether a number is positive, negative or neither and returns 1, -1, 0 respectively. Possibly because the place meeting is actually moving the instance to that position and doing a check with the bounding boxes. Don’t ask me why but it looks already faster. The biggest performance hit are all those place_meeting checks inside the repeat loop. The loops themselves are almost inevitable but we could replace the place_meeting with the collision_rectangle function. There is quite a bit of optimization to be made there. If (!place_meeting(x + sign(vxNew), y, obj_collision_par)) If (!place_meeting(x + sign(vxNew), y, obj_collision_par) & !place_meeting(x + sign(vxNew), y + 1, obj_collision_par) & place_meeting(x + sign(vxNew), y + 2, obj_collision_par)) If (place_meeting(x + sign(vxNew), y, obj_collision_par) & !place_meeting(x + sign(vxNew), y - 1, obj_collision_par)) If (!place_meeting(x, y + sign(vyNew), obj_collision_par)) If you remember Zack’s code, it looks more or less like this ///scr_collision_zack() Looks like I was able to gain some speed here…Īnd as someone once told me “sharing is how better games are made”… so here it is my “improved” version. Recently I started to look into ways to optimize such code without losing the functionality (slopes are a big feature of that simple collision/movement code). As I said in a previous post about my platformer engine (the one I’m working on for Fuzeboy), I’m using Zack Bell‘s code as a base.