Crafty icon indicating copy to clipboard operation
Crafty copied to clipboard

Player Entity gets Stuck on Walls, Walls have slight gap on one side

Open 0xf0xx0 opened this issue 6 years ago • 2 comments

Hello again :wave: Whenever my player is on a wall (Say, facing vertically) and i move into the wall and move down or up at the same time, the player gets "locked" into place. Also, the wall entities have a slight gap on one side only. Wall gap 1 Wall gap 2 Wall gap 3

0xf0xx0 avatar Dec 14 '18 22:12 0xf0xx0

This will depend on how you're performing collision detection/resolution -- it's hard to diagnose without seeing the code!

starwed avatar Dec 24 '18 15:12 starwed

@starwed Code:

.bind('Move', function(evt) { // after enemy moved
    var hitDatas, hitData;
    if ((hitDatas = this.hit('Wall'))) { // check for collision with walls
      hitData = hitDatas[0]; // resolving collision for just one collider
      if (hitData.type === 'SAT') { // SAT, advanced collision resolution
        // move player back by amount of overlap
        this.x -= hitData.overlap * hitData.nx;
        this.y -= hitData.overlap * hitData.ny;
      } else { // MBR, simple collision resolution
        // move player to previous position
        this.x = evt._x;
        this.y = evt._y;
      }
    }
  })

0xf0xx0 avatar Dec 25 '18 01:12 0xf0xx0