A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Tile-based collision detection

Threaded View

  1. #3
    Junior Member
    Join Date
    Dec 2003
    Location
    Netherlands
    Posts
    6
    Thank you for your response Nialsh,

    I always did it that way before, adjusting velocity instead of directly change the position of the object. But it's really not what I want for this project. A player is not supposed to bounce, he has to just stop when he reaches the ground.
    Besides, the ground is like quicksand now, I still need to move the player above/below the tile directly through the x/y coordinates so it won't slowly "fall" inside the tile. And then we have another problem: the bounce will have the player "blink" for 1 vertical coordinate all the time.

    I just don't understand why it's not working correctly. When you move left/right, object.speedX becomes greater or less than zero. Then I check for the edges top left or bottom left if object.speedX < 0 (because the player is moving to the left) and top right or bottom right if object.speedX > 0 (because player is moving to the right).

    So what I noticed is that the bottom edges seem to be inside a tile, causing the player to move very abruptly to the edge of a tile horizontally. But this shouldn't happen since I first check the vertical collisions (top left, top right and bottom left, bottom right) - meaning I put the object above the tiles so it won't collide with the tiles at the bottom at all (for at least one frame).

    But still even after I update the edges, they seem to be inside the tiles below.
    What am I not seeing?

    Edit: so I just changed this line:
    Code:
    object.y = edges["b"] * WORLD.tileHeight - object.height * 0.5;
    to
    Code:
    object.y = (edges["b"] * WORLD.tileHeight - object.height * 0.5)-1;
    and it fixed a lot of problems. But still, I have some issues with jumping against vertically stacked tiles. So for example, if you hold down left/right and want to jump on a tile, it notices that the top edge of the object sticks inside the tile (because of holding the left/right key, you are adding horizontal velocity to the object).

    Any thoughts?
    Demo here: http://murtada.nl/experiments/tiles/v4/
    Last edited by Murtada-King; 08-24-2011 at 11:54 AM.
    -

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center