Author Topic: Issue with collision of boxes and tilemap  (Read 1337 times)

Esti

  • Active Member
  • ***
  • Posts: 104
  • Karma: +0/-0
    • View Profile
Issue with collision of boxes and tilemap
« on: Thu, Oct 25, 2012 »


I am working on a concept that relays on boxes and some puzzles involving simple physics. The thing is I can't fill a hole of 16x16 with a box of the same size withouth having issues. My char gets stuck but if I change the size of the box to 17 my char can't step into the box without colliding with it. Anyone knows what can I do? thanks.

Check it out on Mochi!

auriplane

  • Snails!!
  • Contributor
  • ****
  • Posts: 497
  • Karma: +1/-0
  • Snails!!
    • View Profile
Re: Issue with collision of boxes and tilemap
« Reply #1 on: Thu, Oct 25, 2012 »
When the box is in place, set the tile on the map (to something invisible) and make the block non-solid / inactive.  That way, you're using the tilemap's collision, which is designed to handle consecutive blocks like that.

Obviously, this doesn't solve it in all situations, but it's easy and it works.

Esti

  • Active Member
  • ***
  • Posts: 104
  • Karma: +0/-0
    • View Profile
Re: Issue with collision of boxes and tilemap
« Reply #2 on: Thu, Oct 25, 2012 »
Thanks for the help!. This works but the bad part is that the block has to "know" when it is in place, nothing crazy though.

I have another question, I found this code in the photonstorm tutorial

In the update
Code: [Select]
var tx:int = int(x / 16);
var ty:int = int(y / 16);

if (Registry.map.getTile(tx - 1, ty) >= 31)

is this a good way to find the position of a tile near a moving object? This is part of the code used for the AI of the enemies, more specifically to turn arround when they found an empty tile.
         

Check it out on Mochi!

pWEN

  • Cicadomorph
  • Member
  • **
  • Posts: 85
  • Karma: +0/-0
    • View Profile
    • Portfolio
Re: Issue with collision of boxes and tilemap
« Reply #3 on: Wed, Oct 31, 2012 »
That code is getting the current tile location, then checking the position of the tile directly to the left, and seeing if it's greater or equal to 31. Usually when you do collision with moving objects, you want to do your position +/- (depending on what direction you're traveling) your speed. So if you move at a speed of 5, and you want to check what's in front of you as you travel to the right, it would be if(yourX + yourSpeed >= collidePosition), or something like that.

For detecting if a square is where it should be, you might want to have some kind of invisible square in the end position and do a collision check to see if all four corners of the visible square are within the boundaries of the invisible square. Er... hope that makes sense.

Esti

  • Active Member
  • ***
  • Posts: 104
  • Karma: +0/-0
    • View Profile
Re: Issue with collision of boxes and tilemap
« Reply #4 on: Thu, Nov 1, 2012 »
I get it. Thanks!
Anyway I'm finding a lot of issues with the collision and I find my solutions rather "hackish".

For example I found out that If my player is in a moving platform and there is an obstacle in its way the collision doesn't work properly if I'm not moving and the player get through solid things. Also when I try to attach a sprite to the player to make the illusion the player is carrying it, the player sprite stutters and this "object" the player's carrying also doesn't collide with solid things.

Check it out on Mochi!

pWEN

  • Cicadomorph
  • Member
  • **
  • Posts: 85
  • Karma: +0/-0
    • View Profile
    • Portfolio
Re: Issue with collision of boxes and tilemap
« Reply #5 on: Fri, Nov 9, 2012 »
Sometimes I've found that changing the order of collision checks can help issues like that. Other times... well, embracing technological limitations can still lead to good designs.  :-\