[DM] Block to detect collision at a certain point

Chris

  • Posts: 84
I had an issue described here. While I got a answer on how to solve my problem, I do feel there should be a block in order to check for this.

Epic428

  • Posts: 1118
Just out of curiosity, why couldn't you put in the "When this collides" wrapper a statement saying "If [x of collison] = value and [y of collision] = value then..."

There are blocks that will output the x and y of the collision.

Basically the block that you want created would do this exact same thing, no?
James Moore - Official Support & Documentation.
We cannot and will not respond to PM's asking questions. Please make a new thread in the forums if you have any questions, Thank you.
For better support and faster response times, please post your logs regarding any Stencyl related issues. Debug > Logs > Generate Logs

Chris

  • Posts: 84
I didn't think of that. Thanks, that will work fine.

Alexin

  • *
  • Posts: 3127
Basically the block that you want created would do this exact same thing, no?
No. The coordinates returned upon a collision are contact points - where shapes collide with each other.

What Chris wants is to detect shapes at an arbitrary point. There's a call available in Code Mode that does just that using Ray Casting. It can be simulated by using a very tiny sensor shape to detect collisions.
"Find the fun"
alexin@stencyl.com

Chris

  • Posts: 84
Yikes, I misunderstood. Yeah, I want to detect objects at a certain point. The sensor would work, but having a block for this sort of thing would be great.

Alexin

  • *
  • Posts: 3127
The workaround, for now, is for me (or someone else) to make a CM behavior. You tell it to pick shapes at some point and then retrieve a list of the shapes found (empty list if none was found).

If it works for you I can make it.
"Find the fun"
alexin@stencyl.com

Alexin

  • *
  • Posts: 3127
A sample game is attached with two simple behaviors. Actor Picker is a Scene behavior and is the one that does the real job. Actor Picker Test shows you how to use Actor Picker; take a look at it. Toggle the console and click around the screen to get feedback.

Let me know if you need help.
"Find the fun"
alexin@stencyl.com

Epic428

  • Posts: 1118
Basically the block that you want created would do this exact same thing, no?
No. The coordinates returned upon a collision are contact points - where shapes collide with each other.

What Chris wants is to detect shapes at an arbitrary point. There's a call available in Code Mode that does just that using Ray Casting. It can be simulated by using a very tiny sensor shape to detect collisions.

Yeah, after posting I started to question, and read his post again, I realize now that this was what he was looking for, in which case you are right, my solution would not have worked.
James Moore - Official Support & Documentation.
We cannot and will not respond to PM's asking questions. Please make a new thread in the forums if you have any questions, Thank you.
For better support and faster response times, please post your logs regarding any Stencyl related issues. Debug > Logs > Generate Logs

Chris

  • Posts: 84
It works great, thanks. So, to see if there's an actor right beneath another actor, I'd do y of object + y of camera + 1, right?

Also, judging from the name "Actor Picker," it doesn't retrieve tiles on that spot, right? Would there be a way to?

Greg

  • *
  • Posts: 1259
Unfortunately the call being used doesn't include tiles.  It would be nice if it did. 

Alexin

  • *
  • Posts: 3127
So, to see if there's an actor right beneath another actor, I'd do y of object + y of camera + 1, right?
No. Considering "object" is an actor, then its X and Y are already in scene space, there's no need to add the camera's location.
I did it in Actor Picker Test because I uses the X and Y of the mouse, which is in screen space.
"Find the fun"
alexin@stencyl.com

Chris

  • Posts: 84
Oh, so just "y of object + 1." Okay, thanks.

Joe

  • *
  • Posts: 2478
Alexin, I've been achieving similar functionality by spawning and deleting small regions. Is there an advantage to using Actors?

Greg

  • *
  • Posts: 1259
I don't believe Alexin's approach actually uses Actors -- it simply takes the coordinates of the mouse click and then calls into a Box2d function which determines if that coordinate is colliding with any fixtures (Actors in this case).  I'm not sure which way would be more efficient in the end, spawning a region (in essence an actor) or polling a particular area on the screen for any actors.

I think a big hole in both approaches is that there's currently no way to detect a tile -- and often when you're checking for a collision, tiles are a valid group.  I wonder if we can change, or add a method that would include tiles as well. 

Joe

  • *
  • Posts: 2478
I don't believe Alexin's approach actually uses Actors -- it simply takes the coordinates of the mouse click and then calls into a Box2d function which determines if that coordinate is colliding with any fixtures (Actors in this case).  I'm not sure which way would be more efficient in the end, spawning a region (in essence an actor) or polling a particular area on the screen for any actors.

I think a big hole in both approaches is that there's currently no way to detect a tile -- and often when you're checking for a collision, tiles are a valid group.  I wonder if we can change, or add a method that would include tiles as well.

Ah, I saw "sensor" and mistook it for a sensor Actor. The other big drawback I've found to using regions is that, if you create or move a region, the "for actors in region" block won't report the correct Actors until the next logic step, which can be a pain to work around.