GameMaker Studio 2: Unlocking the Power of Game Development with GML

Math

  • lengthdir_x(len, dir) and lengthdir_y(len, dir) – Trigonometry without the headache. Moves a point len pixels at angle dir.

Part 7: Debugging Like a Pro

GML can be frustrating because it doesn't always crash loudly—sometimes variables just become undefined.

function move_towards(target_x, target_y, speed) 
    var dx = target_x - x;
    var dy = target_y - y;
    var dist = point_distance(x, y, target_x, target_y);
    if (dist > 0) 
        x += dx / dist * speed;
        y += dy / dist * speed;
// Bottom-Right (Front)
draw_vertex_color(_x - _xc + _w, _y - _yc, _col_edge, 1);
// Top-Right (Front)
draw_vertex_color(_x - _xc + _w, _y - _yc + _h, _col_edge, 1);