HTML 5 collision detection platformer game -


i working on platform game , having issues collision detection. game set many blocks next each other or spaced out player jumps 1 block next. right player able jump on top of blocks, run side of blocks , stopped if jumping bottom of blocks. issues having right if in rare scenario player falls on top of part of block, game recognizes side of block block next , player falls through block. if jumping onto edge of blocks[3] , blocks[4] right next it, game recognizes player has jumped side of blocks[4]. idea how can go fixing this? below code collision detection.

function checkblockcollisions() {     // if player collides block, motion should stopped. for(var = 0; < blocks.length; ++) {             var angle = blocks[i].angleto(player);             var thistop = blocks[i].y - blocks[i].height / 2;             var thisbottom = blocks[i].y + blocks[i].height / 2;             var playertop = player.y - player.height / 2;             var playerbottom = player.y + player.height / 2;      if(blocks[i].collideswith(player)) {         if((angle >= 55 && angle <= 360) && player.falling) {         // if player above block, should stop falling.             player.falling = false;             player.onblock = true;             player.setdy(0);               // make sure player not inside block.             player.setposition(player.x, thistop - player.height / 2);                 }                      //top of block lower middle of player top , bottom of block higher middle of player bottom               if(thistop > (player.y - player.height / 2) && thisbottom < (player.y + (player.height / 2 ))) {                 // if player runs side of block, stop sideways motion.                     player.setposition(player.x - player.dx, player.y);                     player.setdx(0);                 } // end if                 else if(player.falling) {                 // if player below block, should keep falling stop accelerating upwards , sideways.                     player.setdy(0);                     player.setdx(0);                     player.setposition(player.x, thisbottom + player.height / 2 + 1);                 } // end if             } // end if         } // end     } // end checkblockcollisions 

check out engine, it's engine written entirely collisions , simple use: https://github.com/murplyx/aae---axis-aligned-engine


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -