(c) copyright Zehne Ziba Co., Ltd. For more information, please refer to copyright notice.
There are three types of physics colliders in Vanda Engine: Static colliders, Dynamic colliders controlled by PhysX engine, and dynamic colliders controlled by animated geometry. Static colliders stay at the same position and never move or rotate during the game. Dynamic colliders controlled by PhysX engine can interact with Player and other objects of your game. They are applied to geometries and control the position and rotation of those geometries during your game. As their name implies, dynamic colliders controlled by animated geometries are attached to animated geometries and their position and rotation are controlled by animated geometries. However these colliders can still interact with objects of your scene, but they can’t interact with Player. In this tutorial, we discuss about the colliders controlled by PhysX engine. We create a simple prefab and assign a dynamic PhysX collider to its geometry.
Importing Box Model
For this tutorial, I use a simple box model. I have already switched to Prefab mode, imported LOD 1 and LOD 2 of box prefab and I’m ready to assign a dynamic physics collider to its geometry. First of all, I make sure that only LOD 1 is visible. Then I select the Box geometry.
Generating Dynamic Collider
Now press PhysX Editor button. Because box collider fits the shape of box model, I use this collider type. We are going to create a dynamic collider, so make sure to specify a non-zero value for density parameter. Larger values create a heavier collider, so pushing and moving it will be harder. I set Density parameter to 2 and leave other parameters unchange. Hit Generate and press OK button to close the PhysX editor.
Testing Dynamic Collider
Switch to Play Mode by pressing the joystick button. Try to push the box mesh. As you see, it reacts to the forces based on the Newton rules. But what about the box object of LOD 2? you are able to walk through it and it doesn’t react to the player. So you should create another collider for LOD 2? NO! Vanda Engine takes care of everything as long as you follow a basic rule: When you save this prefab and insert an instance of this prefab in your VScene, Vanda Engine detects that this box model uses dynamic PhysX collider and looks for the same geometry name in LOD 2 and LOD 3 to change their transformation based on the PhysX calculations applied to LOD 1. So if it doesn’t find the same geometry names, it doesn’t update transformations of LOD 2 and LOD 3 accordingly.
Now we will make sure that both geometries in LOD 1 and LOD 2 of our box prefab use the same name. Make sure that LOD 1 is visible and LOD 2 is invisible, then select the box model. When you select the geometry in geometry based selection, you see the name of this geometry in lower right corner of editor. In my case, selected geometry name is geom-Mesh_Object. Now make sure that LOD 1 is invisible and LOD 2 is visible. Select the box model and take a look at lower left corner of editor. If its name is the same as box model of LOD 1, Vanda Engine will handle the Physics calculations and you don’t need to worry about LOD changes in VScene mode.
Lower left corner shows the name of selected geometry
Now save your prefab and switch to VScene mode (Mode | VScene).
We are going to insert an instance of this prefab in our level and test the dynamic collider. From the main menu of Vanda Engine, go to Prefab | Prefab Editor…. Select your saved prefab and hit Insert button.
Press Joystick button to switch to Play Mode. Try to push the box and move it somewhere. We expect that physics engine of Vanda updates LOD 2 transformations as well. To confirm this, move the camera away from the box. When Vanda Engine switches to LOD 2, you’ll see that box still stays at the same position of LOD 1, meaning that Vanda Engine has updated translation and rotation of LOD 2 based on the PhysX calculations of LOD 1.
[alert color=”blue”] When you exit from Play Mode, Vanda Engine resets the position and orientation of box model to its default values. [/alert]
With physics system of Vanda Engine, your 3d worlds literally come to life. You can move objects and they can react to the environment around them the way you would expect them to in real life. With just a few clicks, you can enjoy the latest physics features seen in today’s games.
Let’s stay in touch!
Never miss a single tutorial, sign up for our monthly newsletter. You can unsubscribe at any time if you wish to stop receiving email newsletters from vandaengine.org