Hello, I'm using the function I got off the wiki for bounding boxes but I'm not able to handle the collision like I want to.
Right now I've got one box that can move and jump, but the problem is I can't make it so it just drops down or stops if I hit the sides or under the box and let's me walk on top of the box. I've tried so many times now, but everytime I fix one bug, another one pops up and ruins it.
I have tried to do setPosX(getPosX - getVelX) then set the velX to 0 for the sides, and setPosY(getPosY - getVelX) and set velY to 0 if under the box, and for the top of the box I do the same thing but disable gravity so the player isn't pushed into the box.
This is what I'm using to figure out which side the player hit the box.
I'd really appreciate some help with this, basically I'm just trying to make a platform the player can stand on.
Although it isn't perfect this code will work it does have abug still :/... Maybe you can find the mistake in it I just tossed it together to test collisions.
It uses allegro 4.2
You can convert to 4.4 if you like.
I know it works, but every time I kept finding bugs I made the code more and more complicated to fix the bugs I found, so I decided to rewrite it again for the 4th or 5th time. This time with help of this awesome community
Edit: Oh I thought you meant the code I posted before I edited the whole post, and I didn't notice the attached file.
Edit 2: Hmm, I gotta convert it to Allegro 5 and I haven't used allegro 4 before, but it helps me a little. Thanks
Perhaps I've overlooked something, but I can't find the code for
in the Collision_Handler.cpp file, these two interest me the most cause I'll only be using rectangles in my program.
Also, I have no idea what this is
What is that called?
I haven't yet learnt what that is, but I have seen it before.
and operators and bit shifting?
I did the correction factors by taking the overlaps and going from there....
That was an abandoned project of mine, even if it did work mostly.
Ah I guess I never wrote those functions....
The thought process was 15 bits of data = 2^15 = 32768 more than enough to correct for a collision.
Then have a sign as well to go with it.
Rect/Rect would be something like
Change the Xs to Ys and you have the y correction function.
Think in 1D for a moment.
Suppose you have two intervals on an axis: (min1, max1) and (min2, max2). They are overlapping and you want to separate them. The first one is stationary, but you can move the second one along the axis either in the negative or the positive direction, until they stop overlapping. Take a piece of paper, draw the diagram and work out the formulas for how much to move in either direction to separate the intervals. Now, in a game, you'll want to move an object as little as possible while still pushing it out of the tile. You have two axes, giving you 4 directions you could move along. Calculate the minimal amount of motion along the X axis required to push the object out of the tile, then do the same for the Y axis, then just choose the one with the minimal amount of motion. Try to work it out on your own.
Think in 1D for a moment.
Suppose you have two intervals on an axis: (min1, max1) and (min2, max2). They are overlapping and you want to separate them. The first one is stationary, but you can move the second one along the axis either in the negative or the positive direction, until they stop overlapping. Take a piece of paper, draw the diagram and work out the formulas for how much to move in either direction to separate the intervals. Now, in a game, you'll want to move an object as little as possible while still pushing it out of the tile. You have two axes, giving you 4 directions you could move along. Calculate the minimal amount of motion along the X axis required to push the object out of the tile, then do the same for the Y axis, then just choose the one with the minimal amount of motion. Try to work it out on your own.
if abs(Bx2 - Px1) > abs(Bx1 - Px2) where x1 is always closest to 0, then go towards left else right, then use the same for y and check both x and y? Wouldn't that work?
It always gave me the correct result when I tried it on paper, and I tried it with different lengths, if the player somehow swallowed the box and some other stuff.
int Get_X_Correction(C_Rect *a, C_Rect *b) code
I'll definitely try this code.
Thanks for the help, both of you!