Bullet collision with walls in a procedural level

S

StrangerMonco

Guest
Hello everyone! Hoping you guys can help me.

Basically, I'm trying to create a procedural level for a top down shooter. So far, I've got the level, I've got player collisions, and the player can move and shoot 360 degree, amongst a few other things.

What I'm having trouble with is getting my bullet instances, colliding with my walls and getting destroyed.

I'm using a DS grid, and it draws wall tiles at specific points which stop the player leaving the level. But when my player shoots, the bullets just go through the walls.

I've tried to use what I have for the player, but it is proving a little bit more tricky that i had imagined.

Some videos just use solid objects with collision events, but since my tiles are drawn in the code, i don't have object instances.

Can anyone point me in the right direct? provide some videos, or links or just some advice?

Cheers!

I've put my code here. I've been following some tutorials, so to some of you, this may look familiar.

The first piece is in a script called "grid_place_meeting".



Code:
var xx = argument[0];
var yy = argument[1];

var xp = x;
var yp = y;

 x = xx;
 y = yy;

var x_meeting = (Level.grid[# bbox_right div CELL_WIDTH, bbox_top div CELL_HEIGHT] != FLOOR) ||              (Level.grid[# bbox_left div CELL_WIDTH, bbox_top div CELL_HEIGHT] != FLOOR);

var y_meeting = (Level.grid[# bbox_right div CELL_WIDTH, bbox_bottom div CELL_HEIGHT] != FLOOR) ||             (Level.grid[# bbox_left div CELL_WIDTH, bbox_bottom div CELL_HEIGHT] != FLOOR);   

var center_meeting = Level.grid[# xx div CELL_WIDTH, yy div CELL_HEIGHT] != FLOOR;

x = xp;
y = yp;

return x_meeting || y_meeting || center_meeting;


I also have a second script which references my first script, called "move". The move script is used in the player Step event, and works flawlessly.


Code:
var hspd = argument[0];
var vspd = argument[1];


if  (grid_place_meeting(x+hspd,y))
    {
    while (!grid_place_meeting(x+sign(hspd),y))
    {
       x +=sign(hspd);
    }   
    hspd =0;
}


x+=hspd;



if  (grid_place_meeting(x,y+vspd))
 {
    while (!grid_place_meeting(x,y+sign(vspd)))
    {
       y+=sign(vspd);
    }   
    vspd =0;
}


y+=vspd;
 
C

chico_haze

Guest
I'm using almost the exact same code in my project. This is the only difference I noticed:

Your code:
Code:
var x_meeting = (Level.grid[# bbox_right div CELL_WIDTH, bbox_top div CELL_HEIGHT] != FLOOR) ||              (Level.grid[# bbox_left div CELL_WIDTH, bbox_top div CELL_HEIGHT] != FLOOR);
var y_meeting = (Level.grid[# bbox_right div CELL_WIDTH, bbox_bottom div CELL_HEIGHT] != FLOOR) ||             (Level.grid[# bbox_left div CELL_WIDTH, bbox_bottom div CELL_HEIGHT] != FLOOR);
My code:
Code:
var x_meeting = (Level.grid[# bbox_right div CELL_WIDTH, bbox_top div CELL_HEIGHT] != FLOOR) ||              (Level.grid[# bbox_left div CELL_WIDTH, bbox_bottom div CELL_HEIGHT] != FLOOR);
var y_meeting = (Level.grid[# bbox_right div CELL_WIDTH, bbox_bottom div CELL_HEIGHT] != FLOOR) ||             (Level.grid[# bbox_left div CELL_WIDTH, bbox_top div CELL_HEIGHT] != FLOOR);
bbox_bottom and bbox_top are mixed up in a couple places.

To have bullets check for wall collisions I use:
Code:
if(scr_grid_place_meeting(x,y)){
   instance_destroy();
}
 
S

StrangerMonco

Guest
Nice! Cheers for the reply dude!

I've just been following some tutorials as I mentioned.

I'm guessing yours works flawlessly?

Again, thanks for the reply, I'm gonna try it out when I have time :D
 
Top