• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

"Invisible box around character" - Character movement gets restricted

C

Carcophan

Guest
Hello everyone.

We are able to draw a usable terrain map with an objects Create event and via additional scripting calls. We are also able to put a player and enemy (with state AI and A* pathing) on the map and they move around 'okay' and only 'sometimes'.

Problem we seem to be encountering is this randomly sized 'invisible box' around the player and/or the enemy, inside the larger overall map.

It seems to exist in every room load, but the 'size' of the invisible box is different each load. It may be 10x3 or 2x14 or 4x4, etc. We can move around fully WITHIN the invisible box, but we cannot move the character out of the randomly sized box to move throughout the rest of the map. We just get stuck in this little prison.

We can click and interact with tiles outside of the invisible box, we just cannot move to them, as if the room is only 4x4 instead of 32x32 tiles. The enemy sees me and the mp_path, but is also confined within its own invisible box and cannot leave it to attack me.


Anyone have any ideas?

Using this shows the proper pathing and tiling with no abnormal red/green areas.
draw_set_alpha(0.3);
mp_grid_draw(global.gridPath);
draw_set_alpha(1);



And the maps are simply created via:
Code:
mWidth = 32;  mHeight = 32;
global.lay_id        = layer_get_id("Instances");
global.grid1_        = layer_tilemap_get_id(global.lay_id);
global.grid1        =  ds_grid_create(mWidth, mHeight);
ds_grid_set_region(global.gridHP1, 0, 0, mWidth, mHeight, 0);
 
Last edited by a moderator:

Yal

🐧 *penguin noises*
GMC Elder
Might it be an issue where you use ds_grid coordinates (measured in tiles) instead of room coordinates (measured in pixels, so most likely 16-32 times larger)?
 
C

Carcophan

Guest
Might it be an issue where you use ds_grid coordinates (measured in tiles) instead of room coordinates (measured in pixels, so most likely 16-32 times larger)?
Thanks Yal.

I looked into that and I don't think that is the issue, but am happy to be wrong.

This is pretty much how it is built:

Code:
global.tileSize = 24;
mWidth = 26;
mHeight = 26;
width_ = room_width div global.tileSize; 
height_ = room_height div global.tileSize;

global.lay_id        = layer_get_id("Instances");
global.grid1        = layer_tilemap_get_id(global.lay_id);
global.grid1        = ds_grid_create(mWidth, mHeight);
    ds_grid_set_region(global.grid1, 0, 0, mWidth, mHeight, 0);

//the for loops to build the map
for ( global.i = 0; global.i < mWidth ; global.i++){
    for ( global.j = 0; global.j < mHeight ; global.j++).....
 

Yal

🐧 *penguin noises*
GMC Elder
How are collision checking / checks where it is possible to move or not done? That's as important as the map itself.
 
C

Carcophan

Guest
How are collision checking / checks where it is possible to move or not done? That's as important as the map itself.
Code:
var hspd = argument[0];
var vspd = argument[1];
//horizontal collision - so set speed to 0
if(grid_place_meeting(x+hspd, y)){
    while (!grid_place_meeting(x+sign(hspd), y)){
      
        x+=sign(hspd);
    }
  
    hspd = 0;
}
  
   //plus the y portion

//and this
var x_meeting = (    ((global.grid1[# bbox_right div global.tileSize, bbox_top div global.tileSize != 0]) ||
                        (global.grid1[# bbox_left div global.tileSize, bbox_top div global.tileSize != 0]))
 

Yal

🐧 *penguin noises*
GMC Elder
Here's the issue:
Code:
bbox_top div global.tileSize != 0]
The y coordinate will always be either 0 or 1 thanks to that != 0 turning it into a boolean. You probably meant to have that OUTSIDE the grid accessor.
 
C

Carcophan

Guest
You probably meant to have that OUTSIDE the grid accessor.
Hmmm.
So how would I change my existing structure then, to account for it to not be in this format?

Code:
var xx = argument[0];
var yy = argument[1];
var xp = x;
var yp = y;
 x = xx;
 y = yy;
 
 var x_meeting = (    ((global.gridHP_[# bbox_right div global.tileSize, bbox_top div global.tileSize != 0]) ||
                        (global.gridHP_[# bbox_left div global.tileSize, bbox_top div global.tileSize != 0]))
                 //and more);  
var y_meeting =    (    ((global.gridHP_[# bbox_right div global.tileSize, bbox_bottom div global.tileSize != 0]) ||
                        (global.gridHP_[# bbox_left div global.tileSize, bbox_bottom div global.tileSize != 0]))
                   // && more);
var center_meeting = (        global.gridHP_[# xx div global.tileSize, yy div global.tileSize] != 0     //and more );
                   
x = xp;
y = yp;

return x_meeting || y_meeting || center_meeting;
 
C

Carcophan

Guest
I didn't understand what you meant at first but re-re-reading it ... i changed global.tileSize != 0]) to global.tileSize] != 0) and it is working much better!!!!

Thank you again Yal!
 
Top