Log In  

I am doing a jump platformer (8px*8px tiled).

My collision is currently detecting (player location + player x/y acceleration). e.g if (y.player + y.acceleration= -1.4), then the collision detection will check the above block.

If the player was in position 100, and acceleration was y-3, then I tell the checkbox, "player position is 97 (100-3), check up block collision".
The checkbox then notifies back that there is a block ahead, if so I cancel next movement.

Problem example: Position 100 was 1 or 2 blocks away from the block, so the player position remains 1 or 2 blocks away from its target after the update.
(The checkbox moves at the speed of the player, by so, the collision occurs either 3 blocks inside the collided block, or 2 or 1).

What can be done so the hitbox check the block ahead the player, and if true, then the player touches the block surface?

So far I have thought of these two potential solutions:

  1. Check multiple times collision until the player match the block surface, so check 3 blocks ahead, if colliding, then check 2 blocks ahead, if colliding, then check 1 block ahead, if not colliding then this is the distance to the block ahead, then update the player position (by such amount of attempts) into the tile direction.

  2. If the player would have collided next, then teleport the player position just next to the collided block surface based on the 8x8 tile position of the block into the map.
P#123930 2023-01-08 07:39

1

if the player is always < 8px per frame, then a single neighbor check will work (see demos/collide.p8).

if speed > 8px per frame (that’s a lot), one of the valid strategy is indeed to run collision check multiple times (eg such that each move is <8px).

other options exists (see how other games on bbs are doing)

P#123940 2023-01-08 08:50

[Please log in to post a comment]