Physics & Constraints Puzzles
These puzzles are used to simulate physics behavior and restrict the movement of objects.
Getting started with physics
Before you can use these Puzzles, you must add the physics module to your application. You can do this at the app creation stage using the corresponding option in the App Manager.
Alternatively, you can copy the module ammo.js FROM the verge3d/build folder TO your app folder BEFORE updating your app to a newer version. The update operation then will automatically add the physics module to your app.
"create physics world"
Initializes the physics engine using the specified gravity and frame-per-second parameters. The default gravity value of 9.8 corresponds to Earth surface conditions. Zero value means no gravity as in space. The higher fps value the better simulation quality at the expense of performance.
Under the hood, this puzzle also enables collision detection and automatic synchronization with graphics.
"create physics body"
Creates a physics body from a specified object, of Dynamic, Kinematic or Static type. Assigns the collision shape: Box, Sphere or Mesh. Sets the mass for the body (valid for Dynamic bodies only). Also works for a list of objects, a group (or a list of groups) or with the all objects puzzle.
Physics body types:
- Dynamic - moved by the physics engine, influenced by collisions and collide with other bodies.
- Kinematic - moved by animation or user action. Dynamic objects will be pushed away but there is no influence from dynamics objects.
- Static - cannot move but collide with other bodies.
- Be sure to apply scale in 3ds Max or Blender as the physics engine just ignores the scale of objects.
- For best results, the origin of your object should coincide with the center of mass.
- Use the snap body puzzle to move Dynamic or Static bodies instead of trying to move the bodies directly.
"remove physics body"
Removes physics from a specified object by destroying the physics body associated with it. Also works for a list of objects, a group (or a list of groups) or with the all objects puzzle.
"physics body params"
Sets parameters for the physics body associated with a specified object. Also works for a list of objects, a group (or a list of groups) or with the all objects puzzle.
- friction - coefficient of resistance of relative motion of solid bodies sliding against each other.
- linear damping - coefficient of resistance that will slow down a moving object.
- angular damping - coefficient of resistance that will slow down a rotating object.
- restitution - coefficient of elasticity (if 0 - body is not elastic like clay, if 1 - body behaves like being made from rubber).
When two bodies collide, friction and restitution parameters of both of them are taken into consideration.
Applies Force, Gravity, Linear Velocity, Angular Velocity, Impulse, Torque, Torque Impulse or Position to the physics body associated with a specified object, in a specified direction in world space. Also works for a list of objects, a group (or a list of groups) or with the all objects puzzle.
- Force - push a body in a specified direction.
- Gravity - assign gravity individually for a specified body.
- Linear Velocity - set movement speed.
- Angular Velocity - set rotation speed.
- Impulse - acts like Linear Velocity but also takes the body mass into account (heavier objects will acquire less speed).
- Torque - spin a body in a specified direction.
- Torque Impulse - acts like Angular Velocity but also takes the body mass into account (heavier objects will acquire less rotation speed).
- Position - set body position (works like the snap body puzzle).
Moves a physics body associated with a specified object, and the object itself, to the position of another object by copying its transform data. Also copies rotation. Does not work with lists, groups or the "all objects" puzzle.
Works similar to apply vector / Position puzzle.
"detect collision" and "collision_info"
Detects if there is a collision at the moment of a specified body with another body (or any body from a list or group). If there is a collision, the puzzle in the "upon collide" slot are triggered, otherwise in the "upon no collide".
The collision info puzzle outputs a dictionary with the following fields:
- objectA - the name of the first colliding body.
- objectB - the name of the second colliding body.
- distance - distance between points of collisions.
- positionOnA - XYZ coordinates of the collision point on the first object.
- positionOnB - XYZ coordinates of the collision point on the second object.
- normalOnB - XYZ components of the normal vector at the collision point on the second object.
If an object is not parented to another object, the constraints will work in world space. Otherwise they will work in the parent object's space - you can select the parent object in 3ds Max or Blender to show up the coordinate axes.
Sets up a constraint to limit object position, rotation or scale along a selected axis. A specified id should be unique, otherwise an existing constraint with the same will be replaced. The "min" and "max" slots specify the range between the movement is allowed.
Sets up a constraint to copy object position, rotation or scale from another object. A specified id should be unique, otherwise an existing constraint with the same will be replaced.
Removes, mutes or unmutes a constraint with a specified id assigned to a specified object. Other constraints assigned to this object (if any) will remain intact.