Simulating dominos in Rapier
The following example is built upon the same core concepts we looked at in the Setting up the world and creating the descriptions section. The example can be viewed by opening up the dominos.html
example:
Figure 12.2 – Dominos standing still when no gravity is present
Here, you can see that we’ve created a simple floor on which many dominos are positioned. If you look closely, you can see that the first instance of these dominos is tilted a little bit. If we enable gravity on the y-axis using the menu on the right, you’ll see that the first dominos falls, hits the next one, and so on until all the dominos have been knocked down:
Figure 12.3 – Dominos falling down after the first one is toppled
Creating this with Rapier is really straightforward. We just need to create the Three.js objects that represent the dominos, create the relevant Rapier RigidBody
and Collider
elements...