Open rontrek opened 5 years ago
First calculate the position of the player based on his pos.x
, pos.y
,
size.x, and
size.y, and then just add or subtract
1` tile depending if
you want left, right, up, or down.
Thanks @Joncom, but that would just be with position only and not knowing about the info of the tile if it is passable. Basically, I would like to get info on the tile if can be walkable and then get the position to move to it. I read somewhere if you can get the tile index? you can get more info about the tile.
You could also combine it with checking ig.game.collisionMap.data to see which tiles are passable. In general, a collision tile with value of 0 is passable, while a tile with a value of 1 is solid.
Thanks, I can see now the results. I understand now that the numbering is also from the collision map tile set image that is used if I'm not mistaken.
Does getTile
and setTile
only works on collision maps? I tried using on my LevelMyMap
variable that is used in loadLevel()
but getting undefined errors.
Can I also get info of a tile if it is also occupied by an Entity?
getTile and setTile work on every kind of map, however note that they take absolute/pixel, not tile, coordinates, and then calculate which tile that is.
An entity on a tile won’t affect the collision map data. Entity collisions are a different thing.
I got it now, thanks for the info.
So is there a way to know if a tile is occupied by an Entity? I need my entity to look ahead if a tile is occupied by another entity so it can decide to move to another tile.
You could loop through the entities array and check if each entity (based on its pos and size) is currently overlapping the tile you’re interested in.
Thanks. I see some examples on how to loop specific entities, but how do you check for a tile overlap vs entity? Is there a command or can you give a snippet example?
Take a look at the code inside ig.Entity.touches. The premise is the same whether you’re checking for entity vs tile, or entity vs entity. Just pretend the tile is an entity with a pos where the tile starts, and a width and height of tilesize.
Thanks. I'm getting somewhere now, but still having issues with it.
btw, any thoughts on this diagonal issue thing? I'm tying my entity routines with hurik's a star plugin that you have commented a few days ago.
Haven’t had a chance to look at that yet, and it’s been a long time since I played with that plugin so I can’t really suggest much off the top of my head.
I see, how about your grid based movement plugin? Any tips on how to move NPCs?
I'm actually trying to make it work with the a star plugin, perhaps you can also give some pointers.
Thanks.
How do I get the x and y position of the surrounding tiles of a player? I am trying to place a NPC beside a vacant tile and to take specific action, not collide or moving at the exact position of the player.