GameMaker Platformer Help

K

Kyle Smith

Guest
so I'm trying to make a platformer game and so far I got basic sprites and objects. the character doesn't go through the walls I can move left and right I have the animations down (but not in the game yet). I would just like to figure how to create gravity and have it work. if someone could help me with that and possibly more I would be very grateful.
 

TheouAegis

Member
Do you know what gravity is? Gravity is the force applied between two objects with mass. A force is an interaction upon an object that will change the motion of that object. A change in motion is known as acceleration. In other words, the value of gravity (which is a built-in variable in Game Maker that you can assign any pixel enumeration to) is the amount of force to be applied to an instance's motion. So what you want is to apply that force to the movement of the instance. As maratae said, that is vspeed+=gravity in a platformer.

The default direction of gravity in Game Maker, denoted by the variable gravity_direction, is 270 degrees - straight down. However, you can change the direction of gravity to any direction you want. For example, you could have gravity_direction in object A constantly updated to be the direction from object A toward object B so that object A will always gravitate toward object B. So in a 2-dimensional field of motion, gravity would be defined as hspeed+=gravity*cos(gravity_direction); vspeed+=gravity*sin(gravity_direction).

vspeed, gravity, and gravity_direction are all tied in together in Game Maker and it will automatically perform the calculations. If you want to do your own calculations with your own variables, just replace vspeed with your own vertical speed variable and gravity with your own gravity variable. DO NOT USE gravity IF YOU ARE NOT USING vspeed!
 
Top