0 Favourites

How do I get collisions working on a tilemap?

  • I am working on a game that uses a tilemap of 32x32 tiles. It uses a Pacman-esque "maze", and the player is also 32x32. Player collisions with the map are not working at all unless I give the tilemap object the Solid behavior. However, this doesn't work as intended - it pushes the player all the way up to the top right tile, and won't allow movement (I suspect because the player is touching collision tiles in the map being that he's 32x32 and only has pathways of 32x32 tiles that are not collision tiles, so if the player is in a vertical tunnel, he's touching walls on either side).

    Is there a way to make a tilemap collidable where it's a perfectly tight fit for the player, without having it push the player around?

    Here's a demo I made using Phaser.js which demonstrates how the movement and collisions SHOULD work: http://games.clowerweb.com/games/thundercastle2/

    And attached is a .capx demonstrating what happens when I try to do the same in Construct.

    (In case you're wondering why I'm doing it in Construct after having already made so much progress using Phaser.js, it's because I'm trying out various engines/frameworks and methods of game creation to see which works the best for me.)

    As a side note, you may also notice that the Pin behavior that's on the PlayerArmor sprite isn't working with 8-direction controls (though, funnily enough, it works perfectly when I use Keyboard Keydown events). If you also know why that is, it would be greatly appreciated if you could answer that one too.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • The only mistake is assuming that a 32 by 32 character can move in a 32 by 32 gap. If you think about it, the edges are exactly aligned, therefore causing a collision event.

    If you make the gap 1 pixel either side wider, or make the player 30 by 30, then it will work as intended.

  • The only mistake is assuming that a 32 by 32 character can move in a 32 by 32 gap. If you think about it, the edges are exactly aligned, therefore causing a collision event.

    If you make the gap 1 pixel either side wider, or make the player 30 by 30, then it will work as intended.

    It doesn't work as intended, because then there's 1px of wiggle room on each side of the player. Tile-based games work on the principle of the tiles and sprites being the same size, thus the player being 1 tile wide and 1 tile tall, and moving in spaces that are 1 tile wide/tall. The grid is intended to be perfectly tight, I just don't want the collision objects pushing the player away from them. In Phaser, a collision is only detected when the player is actively trying to move into the collision object. You can stand against it all you want and it doesn't push you out. This is the behavior I need to get in Construct if possible by removing the "push out" behavior of collisions or something similar.

  • Bump. Anyone?

  • The following thread, especially the responses from Christine and Ashley may be helpful.

    https://www.scirra.com/forum/solved-pixel-perfect-platform-engine-using-loops_p664644?#p664644

    If not, then maybe post a minimal project with step by step instructions in the Bugs section.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread sticky
4,517 857,504
Tinimations's avatar
Tinimations
Unread sticky
1,586 437,352
matriax's avatar
matriax
Unread hot topic
378 33,277
part12studios's avatar
part12studios