[Solved] Top-Down Wall Collision Detection

Get help using Construct 2

Post » Sat Mar 04, 2017 9:27 pm

Hi,

I am working on a very small project, and I've run into an issue.
In the game, the character is a 32x32px sprite, that moves 32 pixels in what ever direction you choose, in a grid. W goes up by 32 Pixels, S goes down, etc. However, in this game, walls will be included. As such, there needs to be a check in place, so the player character does not phase through walls.

I thought I could implement this by creating the wall as a sprite, and adding a boolean to the player character, that will get set to 1, should the player co-ordinates be the same as co-ordinates for a wall sprite. There would also be a check on the player movement, that checks if the boolean is set to 1. If it is set to 1, the player character would then be sent 32 pixels back the way, and then set the boolean to 0.

I'm not entirely sure how to go about this, and was wondering how I would do so. Or even if there was a much more light-weight way to do this. e.g. not having the walls be individual sprites, as there could be thousands per in-game level.

Thanks.


EDIT:I accidentally posted this, originally, in the wrong place. I've moved it here, and I also figured out how to do it.
Solution: dl.dropbox.com/s/pjeusiarv44rt27/Movement%20Example.capx

Basically, there are 4 unique, pink, sprites that move alongside the player. When they intersect the wall sprite, they set the value to the corresponding detection variable to 1. Whilst this variable is set to 1, the player can't move in that direction. If the player moves in any other direction, all the wall detection variables are set to 0.
B
4
Posts: 4
Reputation: 210

Post » Sun Mar 05, 2017 9:00 am

Wouldn't setting solid behavior for wall objects just work better and not require any events?
Zelda Gamekit (my project)



Example capxs:

Zelda-Style Inventory

Zelda Health

3-saveslot system

[url=https://www.dropbox.com/s/d4396pwak0oh7q6/ZeldaDialogueSystem.capx?dl=0]Zelda-like Dialogue[
B
47
S
24
G
30
Posts: 517
Reputation: 19,464

Post » Tue Mar 07, 2017 8:48 pm

That's a thing? Would you be able to explain how I would do this?

Thanks.
B
4
Posts: 4
Reputation: 210

Post » Wed Mar 08, 2017 4:43 am

Here, made you a gif:
Image
Zelda Gamekit (my project)



Example capxs:

Zelda-Style Inventory

Zelda Health

3-saveslot system

[url=https://www.dropbox.com/s/d4396pwak0oh7q6/ZeldaDialogueSystem.capx?dl=0]Zelda-like Dialogue[
B
47
S
24
G
30
Posts: 517
Reputation: 19,464

Post » Wed Mar 08, 2017 4:00 pm

Sounds like an awful complicated way to detect collisions with a wall?

If your walls are solid and your player is solid it can't go through a wall.

You can also use collision detection to stop objects from passing through each other but the solid behavior is simple and works 100% of the time for those situations.
Banned User
B
23
S
6
G
58
Posts: 1,229
Reputation: 34,540

Post » Sat Mar 11, 2017 8:01 am

Darn. Nice.

I shall implement these tips.

Thank you.
B
4
Posts: 4
Reputation: 210


Return to How do I....?

Who is online

Users browsing this forum: rotacak and 5 guests