GMS 2 [Solved] How can I make collisions

Discussion in 'Programming' started by DotCodes, Oct 2, 2019.

  1. DotCodes

    DotCodes Member

    Joined:
    Nov 22, 2018
    Posts:
    2
    Hello!
    I am making a game and I was wondering how to code a collision system with that is compatible with the code for my Movement system. Any help would be greatly appreciated!
    Code:
    hInput = keyboard_check(ord("D")) - keyboard_check(ord("A"));
    vInput = keyboard_check(ord("S")) - keyboard_check(ord("W"));
    
    if(hInput != 0 or vInput != 0){
        dir = point_direction(0, 0, hInput, vInput);
        moveX = lengthdir_x (spd, dir)
        moveY = lengthdir_y (spd, dir)
    
        x += moveX;
        y += moveY;
     
  2. 3dgeminis

    3dgeminis Member

    Joined:
    Jun 21, 2016
    Posts:
    130
    Replace the 2 last lines:
    Code:
    if !place_meeting(x+moveX, y, obj_wall) {x += moveX;}
    if !place_meeting(x, y+moveY, obj_wall) {y += moveY;}
     
  3. DotCodes

    DotCodes Member

    Joined:
    Nov 22, 2018
    Posts:
    2
    Thanks! It worked!
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice