I always wanted to make a game with really good physics interaction that give the player many route to solve the challenges or just to have fun in the world and experiment with interactions but my expirience stopped at Little Big Planet editor because when I tried in other engines I got stuck because I was missing the basics of coding and integrating with the usually cpu stressing physics interactions was a too steep learning curve.
Yesterday I gave it a try again with GM:S 2 built in engine and to my surprise not only my ability of coding a cursor that can interact with world took only a few minutes and some tweaks from the ones I used in other non physics based games but also the built in engine works so much better then it used too. I stressed it by spawning tons of objects and it get only some dips in framerate. I'm really happy and excited about this because some game ideas I have dosen't even require a fractions of what I tested here.
BOUNCY STUFF
A Small Guide
The process of making these physics interaction work is really easy, the only problem come on how Game Maker handles the code run invisible to my eyes so probably you will get into some later problems down the line. Having a written and editable code is always better but that's something I 'll look into future.
Acivating Room Physics
The first step is the easiest one, just go in the Room menu settings and flag Enable Physics
Here you can choose the global gravity settings, keeping in mind that Pixel to meters is a ratio that is gonna interact with Gravity x and Gravity Y
Creating the objects
After having the physics enabled one can already start building the objects to populate the world.
Here I made the wall collision by using a simple rectangular sprite and setting his density to 0 so that would remove the gravitational pull and make it a static object.
Collision Mask
Remember that when using the built in Physic engine the old sprites collision masks don't work anymore instead you have to make new one in the Object>Physics menu by clicking down on the Modify Collision Shape.(Works even better and more accurate then the other one)
Proprieties and Colliding Objects
To have the objects interact with each other you have first to flag the Uses Physics in the main object menu and then you can just add an empty event with the object you want to collide with and you are already set.
Then you can change the parameters to make different kind of objects. To make this heavy wooden ball I cranked way too up the density(just with 10 density look already like it) and made it with very little restitution upon bouncing off another object.
Player Interaction
Then I made a mouse cursor to interact with the world, I made two actually one that is not a Physic object as you can see in the video earlier in the post wich is used just to spawn other stuff with the some code as below. Then I made a duplicate of that one but with activating Physics. I gave it a lot of density so it could push other objects around but it dosen't fall under gravity because I have swapped the code:
x = mouse_x
y = mouse_y
wich make an object float at the mouse coordinates but wont work with Physics object.
So I changed into this using built in variables:
phy_position_x = mouse_x
phy_position_y = mouse_y
wich nullifies the law of gravity for the object keeping it at mouse coordinates.
Here below you can see the showcase of the physics based mouse cursor, still I have to find a way to keep it more steady.
Have a goodday!馃榿