Looking for a way to judge an actors proximity to tiles

colburt187

  • *
  • Posts: 2416
In my top down ship game my ship spawns an actor when a button is pressed,

How will I stop it spawning the actor into a wall of tiles, for example if there are tiles at x + 50 of self spawn actor at x-100 etc,

Anyone got any ideas for this one?

Photon

  • Posts: 2691
Creative use of the Tile API?

Are the actors the same size/smaller than the tiles? If so, maybe you could spawn the actor, have it check the tile spaces that it is sitting on, and then spawn elsewhere if it detects a tile.
Do NOT PM me your questions, because I likely will not respond. If I have replied to your question on the forum, keep using that topic. Thanks!

colburt187

  • *
  • Posts: 2416
Yes the actor is smaller than the tile, he usually ends up inside the tiles. I've not used the tile API before, was that solution using it or can I detect that with normal collisons?

Photon

  • Posts: 2691
I'm not too familiar with the Tile API myself, actually. What I would imagine is that you would take the coordinates of your actor's four corners, and then use those coordinates (through appropriate calculations) to fetch and check for the tiles that would contain those corners.

Running normal collisions is kind of sketchy, because (1) collision is not necessarily checked immediately (you have to get to the collision handler post creation) and (2) spawning completely inside a group of tiles doesn't necessarily cause a collision.
Do NOT PM me your questions, because I likely will not respond. If I have replied to your question on the forum, keep using that topic. Thanks!

rob1221

  • *
  • Posts: 9473
Quote
What I would imagine is that you would take the coordinates of your actor's four corners, and then use those coordinates (through appropriate calculations) to fetch and check for the tiles that would contain those corners.
This is the way to do it.  Download my "Tile API" behavior on the 2.2 StencylForge which has blocks you can use.  It also has blocks for calculating column and row from x and y positions.

colburt187

  • *
  • Posts: 2416
Ok sound promising, do I need to create all the tiles in my scene using the behaviour?

rob1221

  • *
  • Posts: 9473
Nope, you can detect tiles placed in the scene designer.

colburt187

  • *
  • Posts: 2416
Sorry Rob could you give me an idea where to start, how does the behaviour know what tiles are which row and column, I can't fine anything to adjust at the scene etc, I can see the custom blocks but don't now how to use them,

Basically want to be able to detect when a tile is at my ship + 100 or -100.

rob1221

  • *
  • Posts: 9473
Columns go from left to right starting at 0.  Rows go from top to bottom starting at 0.  If you don't care about the tile details and just want to check if there is a tile, then use the "Tile at Row:__ Col:__ Layer:__" block and check if it is not equal to "null".  I put examples in the "Examples" event.

colburt187

  • *
  • Posts: 2416
Ok thanks, I think I've got it working.

MotionTwin

  • Posts: 31
Yop !
I have the same problem :
spawning an actor completely inside a group of tiles doesn't necessarily cause a collision.

But when i spawn inside a Type cause a collision.
Is there any behavior on stencyl 3 solve this?

Thanks !