GM:S 1.4 [SOLVED] Bounce against tiles?

Discussion in 'Programming' started by TheBroman90, Jul 10, 2019.

  1. TheBroman90

    TheBroman90 Member

    Joined:
    Jun 20, 2016
    Posts:
    364
    I'm working on a tile based game where I wan't a projectile to bounce when it hits a wall.
    The projectile moves with this code:
    Code:
    x += lengthdir_x(spd, dir);
    y += lengthdir_y(spd, dir);
    How do I change its direction on impact with a wall tile?
     
  2. FlameRooster

    FlameRooster Member

    Joined:
    Feb 14, 2017
    Posts:
    133
    Do a collision check, if your bullet hits the wall going up, then change the y value to a positive so the bullet goes down.

    Do another collision check, if your bullet hits the wall to the right, then change the x value to a negative so the bullet changes direction to the left.

    You just gotta check for a collision, up, down, right, or left, and then change the x movement to a positive or negative or change the y movement to a positive or negative depending on the angle.
     
  3. TheBroman90

    TheBroman90 Member

    Joined:
    Jun 20, 2016
    Posts:
    364
    @FlameRooster Thanks! My problem was that I had no variables for horizontal and vertical speed. So I did this:
    Code:
    hspd = lengthdir_x(spd, dir);
    vspd = lengthdir_y(spd, dir);
    And then made the variables negative on collision.
     
    FlameRooster likes this.

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