Pretorg
Member
Hello! after a long abscense i am back trying to finish my first projec, it is a 2d topdown game set in space and one of the enemies is supposed to be able to navigate towards the player without hitting anything in the way (pathfinding) because both the player and the enemy ships get damaged if they collide.
It wasn't perfect sometimes the enemy ships collide anyway but that's probably because of it's size compared to the grid and those obstacles, anyway i could live with that.
The problem is that the player can destroy those obstacles and when i use the mp_grid_clear_cell function nothing happens, the AI still detects the cells as occupied.
I have been searching but couldn't find anything here nor reddit about this issue.
This is the code i have been using in the destroy event:
So is there any way to clear those cells without having to create the grid multiple times?
Is there something i am not seeing? afterall the obstacles in the grid get cleared or "updated" with the clear_all function.
Apologies for any badly written parts, english is not my mother tongue
It wasn't perfect sometimes the enemy ships collide anyway but that's probably because of it's size compared to the grid and those obstacles, anyway i could live with that.
The problem is that the player can destroy those obstacles and when i use the mp_grid_clear_cell function nothing happens, the AI still detects the cells as occupied.
I have been searching but couldn't find anything here nor reddit about this issue.
This is the code i have been using in the destroy event:
mp_grid_clear_cell(global.grid, floor(mix / 32), floor(miy /32));
mp_grid_clear_cell(global.grid, floor(mix+32 / 32), floor(miy /32));
mp_grid_clear_cell(global.grid, floor(mix / 32), floor(miy+32 /32));
mp_grid_clear_cell(global.grid, floor(mix+32 / 32), floor(miy+32 /32));
- I have tried:
- several things one of those being mp_grid_clear_all and that works, at this point i tought that the problem had something to do with the coordinates i was using that's the reason for mix and miy, they are variables i made to get an updated x and y coordinates.
- I even tought that it might have something to do with the project itself being buggy it has happened to me before so i installed game maker on a different pc and started a new project to test this with nothing but the neccesary objects and still the same problem.
- But after some more testing i found out that if i create the grid on the step event (for this i have a grid object so every enemy can access it) then and only then the mp_grid_clear_cell works, but i think i remember something about that being a way to have a memory leak or a performance drop as it takes too much resources, and i have seen strategy games made with game maker, correct me if i am wrong.
So is there any way to clear those cells without having to create the grid multiple times?
Is there something i am not seeing? afterall the obstacles in the grid get cleared or "updated" with the clear_all function.
Apologies for any badly written parts, english is not my mother tongue