1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Collision Bug hunt guide.

Discussion in 'Bob's Track Builder' started by Kennett Ylitalo, Nov 4, 2014.

  1. Kennett Ylitalo

    Kennett Ylitalo

    Guide is a bit too much but i'm sure we get to that stage.. If you are beginner in 3D world, if you don't know what is a vertice or edge, watch this 5 part series:
    It takes about 50 minutes, you may skip the second chapter as it is just about mathematics.

    Do you have weird collisions, cars going thru walls and bouncing back, walls that look smooth but still cause horrible accidents, cars stopping dead on their tracks? This is very common but there are few principles to follow when building tracks, knowing them help also identifying what is actually causing them.

    Let's start with simple picture how common methods of collision detection works. (We are not going into HAT-tire collisions, it is special environment optimized for only that type of interaction)

    Edge-to-Face, Edge-to-Edge. (source: wikipedia, GJK algorithm)[​IMG]

    That's it. There are only two types used as it cuts down on calculation complexity, ie it is faster. A lot lot faster.. But there are obvious caveats then: it doesn't work on all possible situations. Some game engines even goes so far that they don't allow any interaction between non-solid, concave shapes or both (Source engine is one example, it cuts down on complexity even further..). gMotor2 can accept all kinds but e still need to make some preparations.

    Stray edges:

    Stray edge is connected to only one face. End of walls is good example, end of anything really. A simple triangle floating in space has 3 stray edges. A quad has 4. Solid object has none. ("edge" in the following pictures are all stray edges. Solid has edges too, of course..)
    [​IMG] [​IMG] [​IMG]

    How do this apply to track building? Well, we need to try our best not to allow player to encounter a stray edge. Ever. Do what yo must, make invisible collision objects, bend, twist. This also applies when we split our meshes (for ex when you make a new "material" cross section to any wall, it is split into two meshes)



    Here we have a wall shape object that is split in two. The car is usually travelling only on one direction so we don't need to think about the first one and how it ends (usually..) But when we have a collision with car (usually it is convex shape, that is very good) that happens exactly on the points of split, we may end up in trouble.

    Close up with the two different collisions. Note, we don't use them at the same time, one has precedence but mostly it is just about which condition happens first.


    We have a trouble. The car meets a stray edge. This may cause the game to decide it is a full vertical edge (which it is). This can cause immense troubles, cars get smashed up when they should just scrape the wall, they come at full stop. Note that edge-to-face is not as precise as edge-to-edge. It is very common to have edge to sink several centimeters inside faces until it is is counted as collision. Also the physics engine, while it runs at 100Hz, well, it is not enough for sub cm precision in every frame when you travelling 330km/h. But how to fix it then?


    Note, this is only one solution and not even very pretty one.. Most likely the better option would be to use a different wall that doesn't not split but one that we don't draw, we just use it as Collision Mesh. Use "Render = off", "shadows caster = off" and Collision = on" on all Collision Meshes. Then use the original as only visual object, marked as "Render = on", "Collision = off" and "shadow = on" (you can reverse "shadows" so that collision mesh also is the shadowcaster but do not use both)

    You have to use imagination when you deal with these issues. Usually the easiest way to fix bugging collisions is to use specially created collision mesh as those are not tied to "it has to look real" rules :) SObjects are notoriusly poor as collision Objects. You have overlapping, stray edges all over the pace, the absolutely worst case scenario. Solid, convex shapes are the best but most often, that is overkill. And we can't avoid concave but we don't actually have to; gMotor2 is very good with that particular geometry compared to other game engines..
    • Beer Beer x 4
  2. Lee Knight

    Lee Knight

    Just a small add to your 2nd last paragraph there Kennett...
    If the collision wall (non-rendered) is also set to cast shadow then the non-collision wall (rendered wall) can also be set to recieve shadows & now using the 2 walls for 2 jobs they should no longer get that ugly shadow conflict that happens when 1 wall is set to both cast & recieve shadows...;)
    • Like Like x 2