Skip to content

Instantly share code, notes, and snippets.

@jonathanhirz
Created April 16, 2015 17:28
Show Gist options
  • Save jonathanhirz/d5819c66b441adca9547 to your computer and use it in GitHub Desktop.
Save jonathanhirz/d5819c66b441adca9547 to your computer and use it in GitHub Desktop.
// -=COLLISION RESOLUTION =-
results = Collision.testShapes(sprite_collider, Main.block_collider_pool);
for(collision in results) {
trace(collision.unitVector);
if(draw_collider) {
debug_text.visible = true;
debug_text.text = 'separation: ' +collision.separation;
} else {
debug_text.visible = false;
}
if(Math.abs(collision.separation.y) > Math.abs(collision.separation.x)) {
// resolve vert, top and bottom
// player is falling down, hits ground
if(collision.separation.y < 0 && v_velocity > 0) {
next_pos.y += collision.separation.y;
v_velocity = 0;
is_in_air = false;
}
// player is jumping up and hits ceiling
if(collision.separation.y > 0) {
next_pos.y += collision.separation.y;
v_velocity = 0;
}
} else {
//resolve horz
if(Math.abs(collision.separation.x) > 0) {
next_pos.x += collision.separation.x;
h_velocity = 0;
is_touching_wall = true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment