Hello I have problem detecting collision side on my blocks. I have world made from 2d blocks and I have player which I can controll ! I want to be able to destroy blocks when there is collission with player + BUTTON E is pressed ! Right now if my player is colliding with 2 blocks at the same time and if I press E BUTTON bouth blocks are destroyed ! So what I want is to destroy only one block at the time !
For example if player is moving right and it has obstacle block I want to destry it when E is pressed but at the same time if there is one more block under player then keep that botom block and destroy only one which is on right side - how to make this happen ? How to detect collision side on my blocks like collision was from left side or right or up or down?
Please help
you can use raycast to detect blocks on your sides when you hold right button and press E and then destroy it.
something like this:
RaycastHit2D hit = Physics2D.Raycast(player_position, Vector2.right, boxlayer);
if(hit.collider.gameobject==box){
Destroy(hit.collider.gameobject);
}