Skip to main content

News

Topic: GetObstructingTile finding obstruction where it shouldn't (Read 4798 times) previous topic - next topic

0 Members and 1 Guest are viewing this topic.
GetObstructingTile finding obstruction where it shouldn't
If I have a person (16x16 px) in a map (16x16 px tiles) touching but not overlapping a wall, GetObstructingTile returns > -1 when it seems like it should be returning -1. Is there a better way to detect if the person would actually be able to move to the given coordinates regardless whether it's touching something or not?
In the attached picture, the person spawns at 1,1 and GetObstructingTile("personName",1*GetTileWidth(),1*GetTileHeight()) returns index 0 (the wall's tile index number)

  • Fat Cerberus
  • [*][*][*][*][*]
  • Global Moderator
  • Sphere Developer
Re: GetObstructingTile finding obstruction where it shouldn't
Reply #1
That's actually correct and not a bug.

The question GetObstructingTile() asks the engine is actually not about whether the person is currently obstructed but rather, "Is it legal for the person to move here?"  For person entities, the person's current X and Y refer to the center of the sprite base, not the top-left corner of the sprite.  If that person is placed at 1,1 (in tile coordinates), its sprite base is now centered on a tile boundary and intersects the wall.  So you are indeed obstructed at (1,1), but not at (1.5,1.5).
neoSphere 5.9.2 - neoSphere engine - Cell compiler - SSj debugger
forum thread | on GitHub

  • Fat Cerberus
  • [*][*][*][*][*]
  • Global Moderator
  • Sphere Developer
Re: GetObstructingTile finding obstruction where it shouldn't
Reply #2
In case you're still confused about the above explanation: When you set the starting location in the map editor, it actually places it in the center of the tile, not the corner.  That avoids you spawning inside the wall to begin with.
neoSphere 5.9.2 - neoSphere engine - Cell compiler - SSj debugger
forum thread | on GitHub