Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ExperiBass opened this issue Dec 14, 2018 · 2 comments
Open

Comments

@ExperiBass
Copy link

ExperiBass commented Dec 14, 2018

Hello again 👋
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

@starwed
Copy link
Member

starwed commented Dec 24, 2018

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

@ExperiBass
Copy link
Author

@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;
      }
    }
  })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants