Verlet physics
Last updated
Was this helpful?
Last updated
Was this helpful?
includes a flexible system. It comes with example objects such as lines, tires, balls, cloth and more. differ greatly from the normal rigid body physics most folks are accustomed to (, , , , etc). The goal of Nez's simulation is not to be a full physics simulation. It is here to provide some neat effects and interactions to jazz up your games.
A few things should be noted up front: the system is not a renderer. It handles the physics simulation. It is up to you to render your meshes and textures on top of the simulation data. Verlet objects can interact with standard but in the name of efficiency they will not interact with each other.
Getting started using the is pretty simple. All you have to do is create a object and call it's Update
method. An example that does this is below. The verlet system has a built-in debug visual system. It is being used here so that you have something to visualize.
The verlet simulation consists of just two objects: and Particles by default have a 0 radius but they can be made as large as you would like. Particles also have mass which is used when integrating movement. You can optionally pin a Particle which will make it fixed in space and you can optionally have Particles collide with normal .
Constraints are just mathematic rules that are solved and adjust the Particle positions. At the very simplest we have a . As it's name implies it will maintain a certain distance between any two Particles. On it's own that isn't very interesting but where it gets fun is that Constraints have a stiffness
property. A low stiffness means that the Constraint will squash and stretch whereas a high stiffness will act more rigid.
Also included is which will keep a specific angle between any 3 points. Note that you are not limited to just these Constraints. The verlet system is built to allow you to implement your own unique Constraints. All you have to do is subclass Constraint and implement the abstract methods. You can make constraints do whatever you want.
In the example above, we used two of the built-in Composites
, Tire and Cloth (both classes are simple subclasses of Composite). Composites are just a container for Particles and Constraints so that managing them is easier. Whenever you have an object that you will be creating multiple times you can just subclass to encapsulate it. You can also create Composites on the fly. Lets take a look at how to do that: