## 10 months ago by ansimuz

I have some bouncing entities that I want to ignore the "one way slopes upward" and do a jump when they touch a solid collision tile. as show in this image

handleMovementTrace: function (res) { // passthrough one way solpes if (res.collision.slope && // slope collision? res.collision.slope.nx == 0 && // slope is one-way upwards? res.collision.slope.ny == -1 ) { // Pass through the walls // this.pos.x += this.vel.x * ig.system.tick; this.pos.y += this.vel.y * ig.system.tick; return; } if (res.collision.y && this.vel.y > 0) { this.vel.y = -this.speed; // bounce upward when it touches a solid tile } // I included the parent code instead of using call to the parent this.standing = false; // pasted the parent class code so the // bouncing forever works if (res.collision.x) { if (this.bounciness > 0 && Math.abs(this.vel.x) > this.minBounceVelocity) { this.vel.x *= -this.bounciness; } else { this.vel.x = 0; } } if (res.collision.slope) { var s = res.collision.slope; if (this.bounciness > 0) { var proj = this.vel.x * s.nx + this.vel.y * s.ny; this.vel.x = (this.vel.x - s.nx * proj * 2) * this.bounciness; this.vel.y = (this.vel.y - s.ny * proj * 2) * this.bounciness; } else { var lengthSquared = s.x * s.x + s.y * s.y; var dot = (this.vel.x * s.x + this.vel.y * s.y) / lengthSquared; this.vel.x = s.x * dot; this.vel.y = s.y * dot; var angle = Math.atan2(s.x, s.y); if (angle > this.slopeStanding.min && angle < this.slopeStanding.max) { this.standing = true; } } } this.pos = res.pos; },

handleMovementTrace: function (res) { // passthrough one way solpes if (res.collision.slope && // slope collision? res.collision.slope.nx == 0 && // slope is one-way upwards? res.collision.slope.ny == -1 ) { // Pass through the walls // this.pos.x += this.vel.x * ig.system.tick; this.pos.y += this.vel.y * ig.system.tick; return; } if (res.collision.y && this.vel.y > 0) { this.vel.y = -this.speed; // bounce upward when it touches a solid tile } // I included the parent code instead of using call to the parent this.standing = false; // pasted the parent class code so the // bouncing forever works if (res.collision.x) { if (this.bounciness > 0 && Math.abs(this.vel.x) > this.minBounceVelocity) { this.vel.x *= -this.bounciness; } else { this.vel.x = 0; } } if (res.collision.slope) { var s = res.collision.slope; if (this.bounciness > 0) { var proj = this.vel.x * s.nx + this.vel.y * s.ny; this.vel.x = (this.vel.x - s.nx * proj * 2) * this.bounciness; this.vel.y = (this.vel.y - s.ny * proj * 2) * this.bounciness; } else { var lengthSquared = s.x * s.x + s.y * s.y; var dot = (this.vel.x * s.x + this.vel.y * s.y) / lengthSquared; this.vel.x = s.x * dot; this.vel.y = s.y * dot; var angle = Math.atan2(s.x, s.y); if (angle > this.slopeStanding.min && angle < this.slopeStanding.max) { this.standing = true; } } } this.pos = res.pos; },