-
Notifications
You must be signed in to change notification settings - Fork 555
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
Colliding with an entity teleports the entity to the top #1184
Comments
the Gravity component is completely separate from the Collision component. add this to your "player" component code: |
@liamnajor That works for the bottom, but not the sides. EDIT: Whoops, I put in an extra equals sign in the first if statement. I had to edit your code a little bit because I was getting errors. It works, but the whole game pauses when I hit an the side of an entity with the this.onHit("Platform", function() {
var hitDatas, hitData;
if (hitDatas = this.hit('Platform')) {
var i = hitDatas.length;
while(i != 0){
hitData = hitDatas[i];
if (hitData.type === 'SAT') {
this.x -= hitData.overlap * hitData.nx;
this.y -= hitData.overlap * hitData.ny;
} else {
this.x = evt._x;
this.y = evt._y;
}
}
}
}); EDIT: After looking at the collision docs, I see the code. It still doesn't work and I get the same result. this.onHit("Platform", function(evt) {
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;
}
}
}); |
Add i -= 1 to my code this.onHit("Platform", function() {
var hitDatas, hitData;
if (hitDatas = this.hit('Platform')) {
var i = hitDatas.length;
while(i != 0){
hitData = hitDatas[i];
if (hitData.type === 'SAT') {
this.x -= hitData.overlap * hitData.nx;
this.y -= hitData.overlap * hitData.ny;
} else {
this.x = evt._x;
this.y = evt._y;
}
i -= 1
}
}
}); That way it'll use all the collision data, rather then just one collision callback. Sorry for the stupid error on my part. The reason the doc code didn't work is it uses only the first set of collision data, and my code did too (except trapped in a loop) until I added |
I have an entity (we'll call it player) that, when colliding with another entity (platform), the player entity gets teleported to the top of the platform. My code is here https://repl.it/@j0rdancodes/Game-4
The text was updated successfully, but these errors were encountered: