Capsule Colliders
By Aaron Holowienka
My task for this week (The first week of month 2) was to implement capsule colliders for our characters. Before this, the player and the enemies were box colliders and now that we have actually models for them, the update process of putting all the vertices into world space every frame, to rebuild the AABB became absurdly expensive. Plus, capsule colliders make the player feel slightly more realistic because they slide off edges and don’t get stuck on corners oddly.Before I began any research on capsule colliders, I anticipated it to be a pretty simple process. However, I quickly found out that that wasn’t the case. I started with doing Capsule-Sphere collision which didn’t turn out to be too bad. I did a simple distance between a line segment and point calculation and checked that against the sum of their radii. This required finding the closest point on a line segment to another point which I accomplished by checking the dot product of the vectors involved, the capsule vector and the vector from the capsule to the point. These calculations show if the closest point is in either of the endpoints or if I have to further calculate. Capsule-Capsule collision was much more complicated because I had to do a distance check between two line segments which requires finding the closest point on both of them. Then I moved on to Capsule-AABB collisions which stumped me. I was having a lot of trouble finding the closest point on the AABB to the capsule, so I then engineered a less elegant, but easier solution. I decided to use what I have already by turning the player into three small spheres that cover his entire body and checking them against AABBs. I found this to surprisingly work well and not be too costly.
Comments
Post a Comment