How do I get collisions working on a tilemap?

0 favourites
  • 6 posts
From the Asset Store
_______ Huge collection of metal fixtures ________
  • 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.

  • 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.

  • Try Construct 3

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

    Try 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.

    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.

  • I know this post was old, but I think it is still relevant.

    I didn't test this, just a theory. I saw some older posts asking. I thought this would be easier than some of the suggestions. I'm not sure if anything in C3 was adjusted for that, but here is a possibly solution if not.

    You can use an invisible object and pin character to the object.

    The invisible object can have 4 or 8 frames that change depending on what direction the player is walking. A frame change can change the bounding box.

    32x32 in a 32x32 is a tight fit. Set bounding box to 30x30 and align it to center-top of invisible object when moving up. The character will stop properly when moving up and it will leave room on sides.

    Center-left when moving left.

    Top-left if moving up-left

    Etc.

    The bounding box will change depending on which way the character is moving, but it will still leave room on sides to prevent accidental collision.

    It should allow movement between 32x32 tiles and should make it look pixel perfect.

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