Victor's Devblog

If you are interested to receive those weekly articles as a newsletter, poke me offline! Automated subscription is disabled because of bots...

Otherwise, Atom feed is here!

Multi Collisions 2 : The Implementation

Implementing Multi Collision

As I mentioned last week, the tricky part isn't knowing which of the world's triangles intersect with the car's ellipsoid, but finding which to ignore. For instance, a flat surface subdivided into many triangles shouldn't count as more than one contact.

The key thing for me to figure out this week(end) was "which triangles to ignore". I came up with the following algorithm:

// 1. find all intersecting world triangles
faceIntersections, edgeIntersections, vertexIntersections = findIntersection(ellipsoid, world)


// 2. remove superseded contacts
contacts = [init from face intersections]
for each edge intersection :
    if edge point isn't on any intersecting face:
        contacts.add(edge intersection)
for each vertex intersection :
    if vertex point isn't on any intersecting face or edge:
        contacts.add(vertex intersection)

// 3. remove similar contacts
sort contacts
remove duplicates

The key part being 2) pruning contacts that are already accounted for. For instance, if an ellipsoid intersects a triangle on its face (= [math] the projection along the triangle's normal of the ellipsoid's deepest point lands inside the triangle = [human] the ellipsoid is clearly above the triangle) but also another triangle on its edge such that the edge point is part of the other triangle, then we can ignore that second intersection (because it's likely that the ellipsoid is above the first triangle and just slightly clipping through towards second triangle). Below, blue triangle is ignored because intersected through its edge which is already accounted for by the red triangle:

Part 3) is not entirely necessary. It is about avoiding processing too many triangles, for instance when multiple colliders are overlapping each other, or when the car drives a ramp/half-pipe with many triangles. In this latter case, it is acceptable to only process new triangles if they significantly differ (in contact normal) from others; this avoids having a stiffer restitution because multiple triangles would push back the car at once in a similar direction. Below, blue triangles are ignored for this reason:

Once all of this is done, we have a list of contacts for each of the car's ellipsoids (hull or tires), and I can apply the same restitution force as before. This gives a significantly better result compared to last week (less jitter) and will be helpful for playing sounds:

Various

- fixed a bunch of warnings
- started working on the structure of my new MaterialDefinition struct that will contain physics properties but also sound & visual feedbacks
- dug out a lot more weeds from my backyard