working version, supports layers and has proper collisions