Verge3D Physics Guide

Verge3D comes with a physics engine that can make you 3D objects behave like in the real world. This feature is especially useful for creating 3D games and AR/VR applications.

As physics backend we use the open source physics engine Bullet, which web version is called Ammo.js.

Contents

Getting Started With Physics

Before you can use physics, 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.

Enabling physics in app

Alternatively, you can add the physics module to an existing app. To do this, copy the files ammo.wasm.js and ammo.wasm.wasm from the build folder of Verge3D installation folder to your app folder.

Using Puzzles

Familiarize yourself with the physics puzzles.

General Recommendations

Creating First-Person Character

First-person character mode can be convenient not only for the shooter and RPG games but for any applications which require investigating large environments. It can be architecture visualizations, e-learning apps and interactive guides, museums and other cultural facilities, and even 3D virtual marketplaces. Besides, you can integrate the first-person character in your VR application making it much more realistic and fun!

For usage example, check out the Snowballs VR demo (also available in the Asset Store).

There are many possible ways to implement FPS mode, but for non-expert Verge3D users we recommend you to follow this short guide to achieve results quicker.

Create a capsule-shaped object which represents your character. Tune its height and width to look more realistic. Make sure you set the center of your object correctly.

Capsule used to simulate character physics

In puzzles, assign dynamic capsule-shaped body to the character and disable its rotational degrees of freedom. This way, you allow your character to move but not rotate. Also, apply disable deactivation to your capsule.

Assign character physics using visual programming blocks

Since character needs a floor (+walls) or ground to walk on, create such bodies using the corresponding create physics body puzzles.

The next step is configuring the camera. The camera won't have any physics assigned since we only need it to be our "eyes." Set the First-Person controls to it but don't assign any collision material (we'll be using full-featured collision detection provided by the physics engine, not basic floor/walls simulation). Also, uncheck the Allow Panning and set Movement Speed value to zero:

Tweaking character in the modelling suite

Now we need to attach your camera to the character's "head." There is no need to create a model for the head, add an empty object called "Head" to the scene, and parent it to the upper part of the capsule model. This way the "head" moves with the character.

By using the additional "Head" object you can attach/detach the camera to/from the character in runtime. To attach the camera use the parent and snap to object puzzles:

Snap/parent camera visual programming blocks

To detach the camera, use the parent puzzle with empty to object field.

Character created! Now it's time to make it move in your scene. In the most basic case, we need to move forward when the user press the up-arrow key. To do so, apply linear velocity vector to your character, which is calculated from the horizontal camera direction. To make your simulations robust you should always apply vectors using the on simulation tick puzzle.

Moving character with visual programming blocks

To move your character on mobile device, you'll need additional "controller" elements. You can create them using 3D objects parented to the camera or with HTML elements.

To move your character in VR mode, you can use the get controller property and get gamepad property puzzles to obtain status of VR controller buttons/axes.

Simulating Car Physics

Realistic simulation of vehicle physics can be really useful in applications like interactive car customizers or racing games.

For usage example, check out the Arcade Racing demo (also available in the Asset Store).

Got Questions?

Feel free to ask on the forums!