Jump to content


Photo

mp_grid instance not completely avoiding


  • Please log in to reply
8 replies to this topic

#1 Lbckf

Lbckf

    GMC Member

  • New Member
  • 243 posts
  • Version:GM:Studio

Posted 25 June 2012 - 04:52 PM

So here's what I got in alarm 1
mp_grid_clear_all(global.grid);
mp_grid_add_instances(global.grid,ground,1);
mp_grid_path(global.grid,path,x,y,player.x,player.y,1);
In room's creation code:
global.grid = mp_grid_create(0,0,room_width/16,room_height/16,16,16);
It works for the most part, but the object that is going to player barely avoids "ground". Ground is a square 32x32 pixel object and solid. The object with the path will avoid the center of ground but still run into the sides and get stuck there. It has worked before, but now I don't know what the problem could be.

What did I do wrong?

Edited by Lbckf, 25 June 2012 - 09:17 PM.

  • 0

#2 Lbckf

Lbckf

    GMC Member

  • New Member
  • 243 posts
  • Version:GM:Studio

Posted 27 June 2012 - 12:17 AM

Okay, here's some more info:
I'm using Game Maker 8.1 Pro
some zombies completely ignore the rule and walk right into ground. Then get stuck there because it is a solid.
They still go to the path correctly, but don't walk around ground
Everything else about them works
Some things are done by other objects using with(other) [reduces lag when only 1 object is handling collisions other that the many objects that are on the screen.]
  • 0

#3 Lbckf

Lbckf

    GMC Member

  • New Member
  • 243 posts
  • Version:GM:Studio

Posted 27 June 2012 - 01:45 PM

mp_grid_draw shows ground as being red, but they still ignore it.
  • 0

#4 Noele

Noele

    GMC Mentor

  • GMC Member
  • 2406 posts
  • Version:GM8.1

Posted 27 June 2012 - 01:58 PM

I suspect what is happening is the calculate path has a different origin start than the sprite using it.

mp_grid simply creates a path through the grid, not a path for a specific instance. Remember that the cells must be large enough so that the moving object placed with its origin on the center of a cell must lie completely inside the cell.

When using the path it creates be careful about the position of the origin of the object. You can shift the path if the origin of the object using it is not in its center but centering the sprite often makes life easier.
  • 0

#5 Lbckf

Lbckf

    GMC Member

  • New Member
  • 243 posts
  • Version:GM:Studio

Posted 27 June 2012 - 05:02 PM

The sprite is 32x32 pixels and centered
The grid is 16x16

Should the grid be 32x32 then because the sprite is 32x32 or should it be 16x16 because it's origin is 16x16?
  • 0

#6 Noele

Noele

    GMC Mentor

  • GMC Member
  • 2406 posts
  • Version:GM8.1

Posted 27 June 2012 - 08:24 PM

From the manual:

In particular the size of the cells is crucial. Remember that the cells must be large enough so that the moving object placed with its origin on the center of a cell must lie completely inside the cell. (Be careful about the position of the origin of the object. Also realize that you can shift the path if the origin of the object is not in its center!) On the other hand, the smaller the cells the more possible paths exist. If you make cells too large, openings between obstacles may get closed because all cells intersect an obstacle.


If you use smaller cells the instance will occupy more of them because it is centered in the cell. Ideally make the instance's collision mask smaller than your grid size or increase the grid size.
  • 0

#7 Lbckf

Lbckf

    GMC Member

  • New Member
  • 243 posts
  • Version:GM:Studio

Posted 27 June 2012 - 10:48 PM

Well, I made the grid size 32 by 32 like the sprite, and the mask a 30x30 ball. It works a lot better now, but if it tries to go around a single ground block it will get stuck at the edge. I've tried a few ways of making it get out of the corner but they all end up with the object just running back into it.
  • 0

#8 Lbckf

Lbckf

    GMC Member

  • New Member
  • 243 posts
  • Version:GM:Studio

Posted 30 June 2012 - 05:05 PM

Do I need to post more information?
  • 0

#9 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14446 posts
  • Version:GM:Studio

Posted 30 June 2012 - 07:14 PM

Post your GMK
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users