OFFICIAL Physics In GameMaker Studio 2 - Part 2


YoYo Games Staff
YYG Staff
Part 2 of our 4 part Physics tech blog series is available now!

In this tech blog we'll be following on from a previous one we posted about physics in GameMaker Studio 2. If you haven't read through that one yet, then we recommend that you do, and that you download the attached *.yyz example from that article as this one follows on from where we left off, and will continue to build on what we have already. You can find the previous tech blog from this link.

In this article, we are going to leave the object interface behind and delve into the GML code for physics in GameMaker. This is a necessary step, as creating physics objects from the UI is fine for very basic stuff, but if you want to have any control over a physics enabled instance, you need to use code as there are no equivalent Drag and Drop™ actions for them. However, as you will see, the transition to code is easy enough as long as you have grasped the fundamentals and have a bit of patience!

In our previous article we set up a room, created some objects and gave those objects some physical properties through the GameMaker Studio 2 object editor. We are now going to convert those UI physics properties into coded physics properties so that we can later permit the user to interact with them. So, to start with, open up the object obj_Floor and give it a Create Event. In this event, we'll add a code block with the following code: