I'm a Unity developer and I use monobehavior functions to dot things like collision detection. I have read about articles about collision detection. Most of them work with geometrical structures like sphere or boxes.

How are complex collisions with no formal and geometrical structures calculated?

  • \$\begingroup\$ Can you give an example of such a scenario? Are you asking about mesh or terrain colliders, or something else? \$\endgroup\$ – DMGregory Aug 14 '17 at 22:48
  • \$\begingroup\$ @DMGregory think both of them. \$\endgroup\$ – virtouso Aug 15 '17 at 18:02
  • \$\begingroup\$ Unless I have misinterpreted the question I think you should create convex hulls seperate to the model and apply them to object instances in Unity ? \$\endgroup\$ – RNewell122 Aug 15 '17 at 20:45
  • \$\begingroup\$ The methods we use will be different depending on the situation, so to make sure we're solving the right problem, it would be best if you edited your question to give an explicit example of a specific collision in your game that you're unsure how to handle. If there are multiple different situations, that's fine, you can always post another question for the next one. \$\endgroup\$ – DMGregory Aug 15 '17 at 23:19
  • 1
    \$\begingroup\$ Are you asking about "a game" in general, or trying to solve a specific problem for the game you are making? We can answer a question about solving problems in your game, but pure curiosity questions about games in theory are usually closed ass too broad or off-topic. \$\endgroup\$ – DMGregory Aug 16 '17 at 0:08

Unity uses those exact same geometric structures under the hood. You just don't see the native code (written in C++) that does those operations. That doesn't mean they aren't there. Unity purposely obscures these from you so you don't have to think about them, and you can just use what they've provided "under the hood". Like a driving a car - you need not know how the engine works - you just use the pedals, gears, brakes and steering wheel.

How are complex collisions with no formal and geometrical structures calculated?

If you're asking about the real world: every atomic nucleus repels other atomic nuclei (except in special cases). Atoms form bonds, thereby creating molecules and ultimately, macro-scale physical objects. As you try to push atoms closer together, they repel each other. This (at least in current physics) is described in the Pauli exclusion principle.

If you coded to replicate that effect, you could create objects without need for a large-scale geometric description, since they would likewise just be described as a point in space and a given influence / force around that point. The combination of those point fields would create the greater field which could handle close range repulsion (impenetrability) for you. The problem then becomes simulating enough of these particles to make a working world without very coarse collision fields. That limitation is why we do not do physics that way, at least in games. Collision geometries are typically cheaper.

P.S. You should know that collision systems consist of two sets of actions: detection & resolution.

Let's look at a simple example describing 1D collisions.

First, detection in 1D. Imagine 2 carriages, A & B, on a train-track. If the front of the first carriage is at the same position, or further along than the back of the second trailer, then there is a collision. Here is your track and two carriages overlapping:

---[A [AB] B]--->

If we found they are overlapping, we need resolution. This can occur in many different ways. One of the simplest is to say, "In real life two carriages cannot be overlapping on a train track. So we must move one or both carriages so that they are no longer overlapping." So we go from the above, to this:

---[A ][ B]--->

Now there is potentially a lot more to that, than meets the eye. If you are writing a very simple game, this resolution may suffice. But if you need more accurate physics, then you may need to calculate bounce force using the force formula f=mv with restitution co-efficient, and then reverse or reduce the velocity of A, increase that of B, or whatever. Realistic computation of physics is a field all on its own.

You can see that it's simple enough to extend this to 2D or 3D. Exactly the same principles apply. First, geometrically describe the object (in the case of carriages using a min and max extent), then check for overlap (detection), then resolve the collision in whatever way is accurate enough for you.

| improve this answer | |
  • \$\begingroup\$ thank you for your long answer. ill accept it when I finished reading it. \$\endgroup\$ – virtouso Aug 18 '17 at 20:17

Not the answer you're looking for? Browse other questions tagged or ask your own question.