AABB Resolution but not working.

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
ernie_avina
Posts: 8
Joined: September 5th, 2020, 1:01 am

AABB Resolution but not working.

Post by ernie_avina » September 24th, 2021, 8:26 pm

I posted about implementing AABB on 2 boxes from a clean chili framework and yall ignored it.
i was able to come up with this.
i have the collision response working if you only move using only one direction at a time.
now when i try and slide the box snaps to another edge thats not where i wanted it to go.
i did my part.
can someone please help me? come on im desperate!!!.
if im asking the question wrong or posting in the wrong format please tell me instead of ignoring me. thank you!
Attachments
zip.zip
(110.59 KiB) Downloaded 204 times

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: AABB Resolution but not working.

Post by albinopapa » September 26th, 2021, 4:13 pm

The way you are handling the collision is missing a key factor, where the collision is taking place.

Let's say you are coming from the top and heading to the right. The first thing your code does is check the direction you're traveling. In this case, we are moving right, so the green rectangle gets pushed to the left side. The first fix for this is to determine which side of the red rectangle in this case the collision happened.

Chili does cover a "naive" approach in his old intermediate tutorial series from 2012-2013. I don't recall which one.

In that series, he determines the side of collision and the amount of correction needed by determining the amount of penetration. For instance, from our example traveling right and down, you'd collide with the top of the red box or the left. If it's the top, you're going to see MOST of the time, the penetration will be more shallow in the Y axis and more deep in the X axis. If you collide with the left, MOST of the time the penetration will be more shallow in the X axis and more deep in the Y axis. The reason I say most of the time is because there might be instances where the penetration in the X and Y axes will be the same. In these cases, you could just determine the amount of penetration, move the green box in the opposite direction by the amount of penetration.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: AABB Resolution but not working.

Post by albinopapa » September 26th, 2021, 4:14 pm

Sorry for the late reply, I guess not many people still visit the forum and I have been busy for the past few months.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: AABB Resolution but not working.

Post by albinopapa » September 26th, 2021, 4:24 pm

There is another way to determine collision and how much correction called Separating Axis Theorem ( SAT ). This took me some time to figure out from all the information on the subject, a lot of the code examples online have errors that the authors never address. Unfortunately, it has been too long since I've used it so don't actually remember how to implement it anymore.

Here's a link that might help get you started.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

Post Reply