[Solved] Top-Down Wall Collision Detection

0 favourites
  • 6 posts
From the Asset Store
Particles support animations, collisions, effects and etc.
  • 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.

  • Wouldn't setting solid behavior for wall objects just work better and not require any events?

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

    Thanks.

  • Here, made you a gif:

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • Darn. Nice.

    I shall implement these tips.

    Thank you.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)