1. Hey! Guest! The 34th GMC Jam will take place between August 22nd, 12:00 UTC (Thursday noon) and August 26th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

Don't teleport into objects!

Discussion in 'Programming' started by Rango, Aug 25, 2018.

  1. Rango

    Rango Member

    Joined:
    Aug 23, 2018
    Posts:
    3
    Hey!

    I'm making a Top Down Shooter where you can teleport towards the mouse, the player just jumps to the postion of obj_cursor. If I click on obj_wall the player teleports into it and gets stuck. Is there a way how to not teleport into it? Like if you click on it it teleports beside the wall or basically just doesn't teleport at all?

    Thanks :)
     
  2. Niels

    Niels Member

    Joined:
    Jun 22, 2016
    Posts:
    809
    Just check for a collision with a wall on the position of mouse x and y when activating teleport

    Example:

    When mouseclick {
    If !collision_point( mouse_x, mouse_y, obj_wall, false, true) {
    Obj_player.x = mouse_x
    Obj_player.y = mouse_y
    }
    }
     
  3. the_dude_abides

    the_dude_abides Member

    Joined:
    Jun 23, 2016
    Posts:
    605
    Wouldn't they want to use:

    if mouse click
    {
    if !place_meeting( mouse_x, mouse_y, obj_wall)
    {
    Obj_player.x = mouse_x;
    Obj_player.y = mouse_y;
    }
    }

    As collision_point would only take into account whether mouse_x / mouse_y was in collision with an object, and not include the dimensions of the object that they want to check for collision with the wall...??
     

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