GameMaker Manual - GameMaker.info (2024)

Moving around

Obviously, an important aspect of games is the moving around of object instances.Each instance has two built-in variables x and y that indicate the position of theinstance. (To be precise, they indicate the place where the origin of the sprite isplaced. Position (0,0) is the top-left corner of the room. You can change theposition of the instance by changing its x and y variables. If you want theobject to make complicated motions this is the way to go. You typically putthis code in the step event for the object.

If the object moves with constant speed and direction, there is an easierway to do this. Each object instance has a horizontal speed (hspeed)and a vertical speed (vspeed). Both are indicated in pixels per step.A positive horizontal speed means a motion to the right, a negative horizontalspeed mean a motion to the left. Positive vertical speed is downwards andnegative vertical speed is upwards. So you have to set these variables onlyonce (for example in the creating event) to give the object instance a constant motion.

There is quite a different way for specifying motion, using a direction(in degrees 0-359), and a speed (should be non-negative). You can setand read these variables to specify an arbitrary motion. (Internally thisis changed into values for hspeed and vspeed.) Alsothere is the friction and the gravity and gravity direction. Finally,there is the function motion_add(dir,speed) to add a motion tothe current one.

To be complete, each instance has the following variables and functions dealing withits position and motion:

x Its x-position.
y Its y-position.
xprevious Its previous x-position.
yprevious Its previous y-position.
xstart Its starting x-position in the room.
ystart Its starting y-position in the room.
hspeed Horizontal component of the speed.
vspeed Vertical component of the speed.
direction Its current direction (0-360, counter-clockwise, 0 = to the right).
speed Its current speed (pixels per step).
friction Current friction (pixels per step).
gravity Current amount of gravity (pixels per step).
gravity_direction Direction of gravity (270 is downwards).
motion_set(dir,speed) Sets the motion with the given speed in direction dir.
motion_add(dir,speed) Adds the motion to the current motion (as a vector addition).

There are a large number of functions available that help you in defining your motions:

place_free(x,y) Returns whether the instance placed at position(x,y) is collision-free.This is typically used as a check before actually moving to the new position.
place_empty(x,y) Returns whether the instance placed at position (x,y) meets nobody.So this function takes also non-solid instances into account.
place_meeting(x,y,obj) Returns whether the instance placed at position (x,y) meets obj.obj can be an object in which case the function returns true is someinstance of that object is met. It can also be an instance id, thespecial word all meaning an instance of any object, or the special word other.
place_snapped(hsnap,vsnap) Returns whether the instance is aligned with the snapping values.
move_random(hsnap,vsnap) Moves the instance to a free random, snapped position, like the corresponding action.
move_snap(hsnap,vsnap) Snaps the instance, like the corresponding action.
move_wrap(hor,vert,margin) Wraps the instance when it has left the room to the other side. horindicates whether to wrap horizontaly and vert indicates whetherto wrap vertically. margin indicates how far the origin of theinstance must be outside the room before the wrap happens. So it is amargin around the room. You typically use this function in the Outsideevent.
move_towards_point(x,y,sp) Moves the instances with speed sp toward position (x,y).
move_bounce_solid(adv) Bounces against solid instances, like the corresponding action. advindicates whether to use advance bounce, that also takes slanted walls into account.
move_bounce_all(adv) Bounces against all instances, instead of just the solid ones.
move_contact_solid(dir,maxdist) Moves the instance in the direction until a contact position with a solidobject is reached. If there is no collision at the current position, theinstance is placed just before a collision occurs. If there already is acollision the instance is not moved. You can specify the maximal distanceto move (use a negative number for an arbitrary distance).
move_contact_all(dir,maxdist) Same as the previous function but this time you stop at a contact withany object, not just solid objects.
move_outside_solid(dir,maxdist) Moves the instance in the direction until it no longer lies within a solid object.If there is no collision at the current position the instance is not moved.You can specify the maximal distance to move (use a negative number for anarbitrary distance).
move_outside_all(dir,maxdist) Same as the previous function but this time you move until outside any object,not just solid objects.
distance_to_point(x,y) Returns the distance of the bounding box of the current instance to (x,y). (If the instancedoes not have a sprite or mask, the result of the function is undefined.)
distance_to_object(obj) Returns the distance of the instance to the nearest instance of object obj. (If the instanceor object does not have a sprite or mask, the result of the function is undefined.)
position_empty(x,y) Returns whether there is nothing at position (x,y).
position_meeting(x,y,obj) Returns whether at position (x,y) there is an instance obj. obj can be an object, an instanceid, or the keywords self, other, or all.

« Game play | Paths »

GameMaker Manual - GameMaker.info (2024)

FAQs

Is GML similar to C++? ›

They're both procedural languages... a lot of people don't like to hear this, but they're all basically the same.

Is GML hard to learn? ›

GML is significantly easier to learn and use than many other languages. However, if you're familiar at all with more complicated languages, GML will most likely be a breeze to learn and implement. The learning curve for GML is thankfully not too steep.

Is GameMaker easy for beginners? ›

Is GameMaker good for beginners? Yes! GameMaker Studio is relatively easy to learn compared to other game engiens like Unity or Unreal, as you can make a game without very much code or scripting. However, the games made in GameMaker are geneallly not as complex as with other game engines.

Is GML similar to Python? ›

GML is designed specifically for GameMaker and shares some similarities with languages like C and JavaScript, but it is not Python. However, it's possible to use Python or other programming languages for certain tasks within a GameMaker project by using external libraries or DLLs and interfacing them with GML.

What coding language does GML use? ›

GameMaker Language (GML) is GameMaker's scripting language. It is an imperative, dynamically typed language commonly likened to JavaScript and C-like languages.

Is GML like Java? ›

No, GameMaker does not use Java for its game development process. GameMaker Studio, developed by YoYo Games, utilizes its own scripting language called GameMaker Language (GML). GML is a C-like language specifically designed to be used within the GameMaker environment.

Is Unity harder than GameMaker? ›

Gamemaker Studio 2 comes with an integrated visual scripting solution, which is more user-friendly for novices and people who would rather work without code. User Interface Design: Unity offers a more intricate, feature-rich, and highly customizable user interface.

Does GameMaker require coding? ›

Does GameMaker require coding? No, not for basic games thanks to its DnD system. However, as your game complexity increases, using GML becomes almost inevitable. It is highly recommended to learn GML to harness the full potential of GameMaker.

Is GameMaker 100% free? ›

Which version of GameMaker is right for me? Yes - all versions of GameMaker are completely free to download. You'll only need to pay if you plan to release your game commercially or if you'd like to export your games to Console platforms.

Is GameMaker free now? ›

GameMaker is Free for general use. You may purchase a commercial licence to sell and distribute your games en masse if you like - See the Get page for GameMaker Professional. Enterprise subscriptions are available for console developers.

Can you make money with GameMaker? ›

You'll be in great company if you do decide to monetise your GameMaker titles: some of the most successful indie games of all time were made with GameMaker, including Undertale, Hyper Light Drifter, and Hotline Miami.

Is GML statically typed? ›

GML is a dynamically typed language, and a lot of language features are built around that.

Is GameMaker Language similar to C#? ›

Traditional GML syntax shares similarities with C#, so if you're already comfortable with GML it is a familiar transition.

Is there anything better than Python? ›

Ruby is a fantastic programming language that is among the better Python alternatives and can be used in place of Python. It has gained popularity due to its user-friendly features and syntax. Ruby offers similar properties to Python, including readability, simplicity, and productivity; the two are related.

Does GameMaker use C++? ›

While it has its own scripting language called GameMaker Language (GML), which is similar in syntax to C, GameMaker itself is not primarily programmed using C++. However, GameMaker does provide functionality for more advanced users to extend the capabilities of their games through the use of "extensions".

Which language is most similar to C++? ›

Rust is a multiparadigm, compiled programming language that developers can view as a modern version of C and C++. It is a statically and strongly typed functional language. Rust uses syntax similar to C++ and provides safety-first principles to ensure programmers write stable and extendable, asynchronous code.

What does ++ mean in GML? ›

++, -- are used to add or subtract one (1) from a value. It is worth noting that placing this before or after the value to be added to or subtracted from will have slightly different results. For example: ++a will increment the variable and return the incremented value.

References

Top Articles
Latest Posts
Recommended Articles
Article information

Author: Terence Hammes MD

Last Updated:

Views: 5771

Rating: 4.9 / 5 (49 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Terence Hammes MD

Birthday: 1992-04-11

Address: Suite 408 9446 Mercy Mews, West Roxie, CT 04904

Phone: +50312511349175

Job: Product Consulting Liaison

Hobby: Jogging, Motor sports, Nordic skating, Jigsaw puzzles, Bird watching, Nordic skating, Sculpting

Introduction: My name is Terence Hammes MD, I am a inexpensive, energetic, jolly, faithful, cheerful, proud, rich person who loves writing and wants to share my knowledge and understanding with you.