I have 2 rectangles, one rectangle is player, other one is just box. When player intersects with the box, player’s direction changes along the x axis not y axis. If player intersects with the box from left or right side there is no problem, he coming to the box, turns back and go away but if intersects from up or down side, players starting shaking, goes in box, changes direction, moves a little bit but doesnt escape from box and changes direction again moves a little bit… How can i solve this situation, i want to doesnt check intersections between playerbox and boxbox until player escapes from box but i dont know how can i do that ?
Are you using any frameworks like Slick2D odr LibGDX? Or did you implement everything by yourself?
yes, slick2d
for (Player player : Main.players) {
for (Box box : boxes) {
if (player.intersection_rectangle.intersects(box.intersection_rectangle)) {
if (box instanceof RedirectionBox) {
RedirectionBox r_box = (RedirectionBox) box;
r_box.apply_effect(player);
}
}
}
}
apply_effect just multiply direction value by -1.