Actor on tile detection?

zcstrife

  • Posts: 9
Hi,

I'm really struggling for now 2 weeks or more trying to figure out how I could detect that my actor is walking on a specific tile.
My game has a top down view, so i need to change the actor behavior(speed, animation) while walking on specific tiles. Those tiles appears in many places on the  different scenes.

My players doesn't collide with tiles, and my tiles have specific collision bounds.

Please, let me know if you can help.

Thanks

« Last Edit: October 18, 2016, 03:21:41 am by zcstrife »

MattHutchings

  • Posts: 224
Hi there,
On your player behaviour maybe try something like this. First of all find your tile you want the behaviour to effect get its X and Y coordinates.
If (X of Player is > Tile X) and (X of Player is < Tile X + Width of Tile) and (Y of Player is > Tile Y)  and (Y of Player is < Tile Y + Height of Tile).
Then perform actions...
Maybe a boolean that is set when this is true then just use that boolean to say the player is on that tile.

Hope this helps, if you get stuck let me know.
Matt.

zcstrife

  • Posts: 9
I'm not sure I understand.
These tiles i can place them anywhere on the scenes.
I already tried something like in the attachment. Adding "rocks" to my tile's data. But it doesn't do anything. And I would still have a problem, i can't find out the collision bounds

Edit:Ok this is stupid, i put coordinates where it asks for row and column

Actually, I would love if it was as simple as colliding with actors (as sensors).

« Last Edit: October 18, 2016, 03:37:48 am by zcstrife »

zcstrife

  • Posts: 9
Ok, this kind of work, but not correctly, still have to figure out why.
The only problems is that with this method I can't detect the collisions bounds of each tiles.

Again, it would be so much more easy if the tiles could act like actors, having collision bounds, and being sensor.

MattHutchings

  • Posts: 224
Try this instead,
1. Create a new actor called SpeedTile.
2. Add your animation that you had on it when it was a tile.
3. Navigate to your new actor's collisions tab and set it to sensor.
3. Place your new SpeedTile actor on your scene (make a note of the X and Y positions, from either the bottom left corner or the Inspector next to the palette).
4. Create a new actor behavior and call it SpeedTile Properties. Then attach it to your new actor.
5. Go to your Player behavior and create the same as the image.
6. Go to your SpeedTile Properties behavior and create the same as that image.

Note: The 100 and the 200 are an example of the X and Y of the SpeedTile this will need to be set to where you've got yours placed in your scene, also the SpeedTileWidth and SpeedTileHeight is a game boolean which is optional if you already know this then you can simply ignore the SpeedTile Properties behavior all in all, I just find it cleaner to have things labeled. Then if you want to do this for a second and so on use a otherwise if after your first if in the Player behavoir.

Let me know how you get on. Worst case PM me an i'll help your sort this.
Matt.

zcstrife

  • Posts: 9
I'm sorry but I really don't understand what you want me to do here.
I don't get why you say "2. Add your animation that you had on it when it was a tile." When my actor was a tile? It never was.
Anyway, let's not focus on what attributes or animations will change.
Looking at my screenshots:
Let's say the white dot is my actor.
I want to detect when my actor is colliding with the dark tiles. If he is then things happen, if not, others things happen.
That simple.


My actor moves on the scene following mouse click, but that's just a detail for you to understand what i'm trying to accomplish here

My "speed tiles", as you call them, will come in many different shapes, it would be a mess to create an actor for each of them. And there would be a lot of them on my scene.


« Last Edit: October 18, 2016, 04:48:18 am by zcstrife »

MattHutchings

  • Posts: 224
Okay so I've created an example game for you to mess about with and see how the method i'm explaining works. I've attached a game export to this post so that you can import it. Is this what you're looking for?
http://www.stencyl.com/game/play/35423

Hope this helps,
Matt.

zcstrife

  • Posts: 9
It looks like what i'm trying to achieve. But I can't change all my tiles into actors.
My player will be walking on a more complex map, made of different tiles(not just plain squares like in the example)
The tiles won't have specific positions on the map, the map will be huge, i can't just make condition based on known x,y coordinates of my tiles, because i might change their location in the future.

I'm starting to wonder if I can have tiles that have properties for the players.
Imagine I have a tileset to draw mountains on my scene.
When i place those tiles on the scene, I want my actor to slow down while going throught those tiles. I don't know in advance how i will be placing those tiles though.
Using too many actors would make the game's performance really bad.

If a specific tile's collision bounds is shaped as half a square, i want the player to slow down only when colliding with this shape. I'm really starting to think this is impossible in stencyl

zcstrife

  • Posts: 9
Ok, this kind of work, but not correctly, still have to figure out why.
The only problems is that with this method I can't detect the collisions bounds of each tiles.

Again, it would be so much more easy if the tiles could act like actors, having collision bounds, and being sensor.

I made a mistake, reversing col and row, now it works properly.
The only problem I have, is that I wish i could add a "if is within collision bounds of the tile".

BMJ

  • Posts: 278
I've read everything you've said and I really don't understand why you wouldn't just use actors. In terms of performance, you don't need to worry about the size of your map and how many actors will exist on it. All that matters for performance is how many actors *are currently on screen*. You can have tons of actors offscreen and it will not affect your performance too much, because Stencyl isn't drawing/updating/testing them until they are on screen. Just use actors with sensor collision shapes. You may have to make many of them, but what's the problem with that?  You were going to make many tiles, too, only now they would be actors and they would mostly be offscreen at any given time, so performance shouldn't be a problem. Also, if they are actors, you can scale/tint them for more variety, thus reducing how many you need to make. I have an overworld map with just such requirements, and I have used actors to accomplish exactly what you want. It works great and performance isn't a problem because the vast majority of them are offscreen. Stencyl is at it's easiest when you use actors whenever possible.

Also -- if it were possible to have a tile with all the capabilities you are looking for, it would essentially become an actor, because tiles are basically stripped-down, barebones actors by another name. To add polygonal sensors to tiles would be to essentially turn them into normal-physics actors that can't be moved ... so just use normal-physics actors that can't be moved. It's virtually the same thing. :)   (If you want to scale them, make sure you set the physics to "cannot be pushed", instead of "cannot move".)

Also also -- be sure that your actors do not have the "always simulate" behavior, or they will continue to affect performance when offscreen.

« Last Edit: October 18, 2016, 08:41:12 am by BMJ »

tigerteeth

  • Posts: 733
I'm sorry but I really don't understand what you want me to do here.
I don't get why you say "2. Add your animation that you had on it when it was a tile." When my actor was a tile? It never was.


Literally the first line of his instructions said "create an actor called speedtile".


Anyway, let's not focus on what attributes or animations will change.

But that is exactly what you want to focus on. Everything that you want to do is done very simply, by affecting the attributes of your main character when it collides with something else. All you need to do is use actors instead of tiles, and then use the standard collision system.

Quote
I'm really starting to think this is impossible in stencyl

Take 5 minutes to look at some of the games in the recent stencyl jam on game jolt, and others in the Made in stencyl section, to get a good idea of what stencyl is capable of. What you're trying to do is very, very simple (as long as you use actors and not tiles).

zcstrife

  • Posts: 9
Thank you BMJ & tigerteeth for clarifying things for me.
I don't know where exactly, but I read before that we had to use as less actors as possible in stencyl for performance.
Anyway, if using actors won't affect performance, that's great, I'll use actors then. I didn't know what "always simulate" was for, thanks again.
The only thing is that I have a tileset made of 72 tiles for my mountains, meaning I will have to create 72 actors. It will be a little messy to manage and harder to place them on the map. And It means that my scene will sometimes be completely filled with actors.
Also, how can I detect actors are not colliding (my player is not inside the collision bounds of my mountains)

By the way, sorry, english is not my native language, I got confused.
Thank you everyone.

 

« Last Edit: October 19, 2016, 02:18:54 am by zcstrife »

BMJ

  • Posts: 278
The way to test for "no collision" is to have a Boolean attribute (call it "Collided", for example) that is set to FALSE at the end of the "when updating" loop. Also, in your actor's collision event, set the attribute Collided = TRUE. Collisions events happen first, then 'updating' then 'drawing', so that will result in the default state being Collided = FALSE and will only equal true if the actor is currently colliding.  It will stay true for the duration of the logical frame and then automatically be reset to FALSE at the end of the logical frame.

As for the many actors stuff -- also make *certain* that continuous collisions is turned off for all these actors. This will help reduce the processor workload dramatically. (Continuous collisions is only necessary for very fast moving small actors (like bullets or something similar). It is also turned on by default when you create a character  (something I think the Stencyl team should seriously reconsider. )

When you say the screen will be filled with actors -- how many, roughly, would that be on screen at any one time?

BMJ

  • Posts: 278
Actually, Liberado has described a better way to handle the "test for no collision" dilemma in this thread:

http://community.stencyl.com/index.php/topic,49280.msg272803.html#msg272803

His way accounts for the need to reference the attribute from any event at any point in the logical frame (there are other behaviors that have 'updating' events as well as other actors that may need to reference this actor's Collision attribute) , and is more reliable. I must have only been referencing my Collision attributes in ways that were compatible with my method, but I can certainly see how his method is quite a bit better, for sure.

zcstrife

  • Posts: 9
Hi BMJ and thank you for your answer. I tried using a boolean with "when the player hits something else" or "actor of type", etc... but it seems the collisions are only detected around the edges. So whenever the player doesn't touch the border while being inside the other actor collision bounds, colliding is set to false. I might need to do more test, but it seems this is how it works.
When you think about it, it's quite logical, since the block is called, when the actor hits something else. Meaning, it only occurs when it hits something, not while it collides?

Oh and if my screen is filled with actors, actually not that much, 60 max.

« Last Edit: October 23, 2016, 04:57:42 am by zcstrife »