Hey,
In my game I have these enemy's that have this simple ai grid pathfinding that I used from this itch.io page. https://randatabase.itch.io/simple-ai-grid-pathfinding
It does what it's supposed to do but I have a little problem.
I have this system where is randomly spawns a certain amount of tree's on a 64x64 grid and it looks quite nice but the enemy is not colliding with these randomly generated trees. It just walks right through it. The only time it ever does collide is when I purposely place a tree object in the room and THEN it walks around it. Which is what I want.
Here's the code the code from the Tree Spawner. (ObjTreeSpawner)
And I'm only going to paste a little snippet from the AI example where I think the problem is happening.
This is inside an object called controller_grid
Specifically the line - mp_grid_add_instances(global.grid,ObjTree,false);
Can anyone help me out?
In my game I have these enemy's that have this simple ai grid pathfinding that I used from this itch.io page. https://randatabase.itch.io/simple-ai-grid-pathfinding
It does what it's supposed to do but I have a little problem.
I have this system where is randomly spawns a certain amount of tree's on a 64x64 grid and it looks quite nice but the enemy is not colliding with these randomly generated trees. It just walks right through it. The only time it ever does collide is when I purposely place a tree object in the room and THEN it walks around it. Which is what I want.
Here's the code the code from the Tree Spawner. (ObjTreeSpawner)
Code:
CREATE EVENT
var cellSize = 64;
var columns = room_width div cellSize;
var rows = room_height div cellSize;
var grid_xArray = array_create(0);
var grid_yArray = array_create(0);
var count = 0;
while (count < 300) //Change number to how many objects you want to be spawned
{
var c_pick = irandom_range(0, columns);
var r_pick = irandom_range(0, rows);
if (count > 1)
{
var n = array_length(grid_xArray);
for (var i = 0; i < n; i++)
{
if (grid_xArray[i] != c_pick)
{
if (grid_yArray[i] != r_pick)
{
count++;
array_push(grid_xArray, c_pick);
array_push(grid_yArray, r_pick);
break;
}
}
}
}
else
{
count++;
array_push(grid_xArray, c_pick);
array_push(grid_yArray, r_pick);
}
}
var n = array_length(grid_xArray);
for (var i = 0; i < n; i++)
{
var xx = grid_xArray[i] * cellSize;
var yy = grid_yArray[i] * cellSize;
instance_create_layer(xx, yy,"Collision", ObjTree); //Collision is a name for a layer I have
}
This is inside an object called controller_grid
Specifically the line - mp_grid_add_instances(global.grid,ObjTree,false);
Code:
CREATE EVENT
//Size of Cells
var cellWidth = 64;
var cellHeight = 64;
//Amount Of Cells
var horCells = room_width div cellWidth;
var verCells = room_height div cellHeight;
//Create Grid
global.grid = mp_grid_create(0,0,horCells,verCells,cellWidth,cellHeight);
//Add Collision Object To Grid
mp_grid_add_instances(global.grid,ObjTree,false);