Created
April 16, 2015 17:28
-
-
Save jonathanhirz/d5819c66b441adca9547 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// -=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