Collision detection with grid-based movement

Get help using Construct 2

Post » Wed May 29, 2013 5:32 pm

Hey everyone!

I'm putting together a game that's using a tile(or grid)-based movement sample that was provided by someone here on the forums (can't remember off the top of my head who it was, sorry.) I've been able to adapt the example to do handle the movement exactly as I want, but I can't seem to figure out how to handle collision detection now. The solid behavior with collisions turned on has no effect, and I think it's because using the movement controls actually causes the sprite to "warp" to the next space rather than "sliding" into it if that makes any sense.

I tried adding a few conditions for "if player is not overlapping enemy" which sort of works, but it won't allow you to move onto any adjacent square to the enemy either, which I believe is due to the bounding box, but if I modify the polygon, it allows you to move right through the enemy sprite again... so basically I need a way to check if the space you're trying to move onto contains an enemy sprite or not and prevent you from moving if there is. Any ideas how I can implement this? The capx of the movement stuff is available here
B
8
S
1
Posts: 34
Reputation: 938

Post » Wed May 29, 2013 8:08 pm

Hi
I have a solution for you.

Capx
http://drappdev.net46.net/Construct2/MySolutions/topic68600_solution.capx

Live
http://drappdev.net46.net/Construct2/MySolutions/topic68600/

Hope this helps

DR App Devdrappdev2013-05-29 20:10:41
B
14
S
4
G
3
Posts: 21
Reputation: 2,164

Post » Wed May 29, 2013 11:03 pm

The live demo seems to work perfectly. Thanks! :)
B
8
S
1
Posts: 34
Reputation: 938

Post » Wed Dec 25, 2013 3:53 pm

What was the resolution to this? The links provided in the answer don't work.
B
17
S
3
Posts: 33
Reputation: 1,646

Post » Wed Jan 22, 2014 2:57 pm

Hmm, it appears the capx file has been taken down, but the link for the live version still works so you should be able to test it out. Basically, there's an object that defaults to the same position as you, and when you press to move in a certain direction, it moves there first to detect if the space is free or not. If the space is free, your sprite moves and if not, it doesn't. In the example the helper object is made visible as a green square but you would obviously want it to be invisible. I put the capx up on my dropbox (https://www.dropbox.com/s/dt3z6vohps1zn8n/topic68600_solution.capx).

Now that C2 has a tilemap object, I'm not sure if this would be necessary or not anymore. I haven't played around with it to test it out, but hopefully this helps in the meantime.
B
8
S
1
Posts: 34
Reputation: 938


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 10 guests