hello.
I am working on a strategy game, and i made a few models of collisions between rectangles in the past but now i need it to be precise and the code to be versatile.
i am not going to show you all my 8 classes, because you're not gonna read them . so, i will simplify it to that:
i have two rectangles, rectangle 1: player, rectangle 2: wall. (doesn't really matter)
every frame, i call the method:
public String collision(int x1, int y1, int width1, int height1, int x2, int y2, int width2, int height2){
}
and i want it to return right/left/up/down/none. for example, if rectangle 1 collides rectangle 2 from above, it will return up. if it doesnt collide at all, it'll return none.
can you please show me example code, or tell me the theories behind this? i dont have a problem when it is just a big wall, but when it can collide from all directions.... it gets a little harder, especially when Y axis is f***ing in the wrong direction!.
I want it to be good. for example, there are two rectangle colliding horizontally. the left one is controlled by a human, and is moving right AND up. when the rectangle reaches above the other one, it should not jump some distance up or right but smoothly continue moving. it depends on other things, but on this too!
by the way, what do you recommend doing when it does collide and if i detect it? make speed=0 and return the x or y location to the limit of collision?
any help would be very appreciated.
thanks