Collision detection with grid-based movement

0 favourites
  • 5 posts
From the Asset Store
Grid - snap to grid
$1 USD
80% off
Snap to visible grid - perfect solution for any game genre
  • 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

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The live demo seems to work perfectly. Thanks! :)

  • What was the resolution to this? The links provided in the answer don't work.

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

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