Get The Most Out of 3D Physics For Creating A Game in Unity
Making games in Unity has become a popular thing. Unity3D games have literally flooded the entertainment industry. We have previously discussed what Unity is and the things you can do with it. Now the time has come to discuss 3D physics Unity. The basic question that pops up:
Is 3D physics important for creating a 3D game in Unity? The simple answer: it all depends on what type of game you want to have. If you want to have a VR game where game objects behave realistically, then, Unity 3D physics is a must.
Let’s look at some main components of Unity 3D Physics. Then you will be able to see how important physics is by using our VR simulation game as an example.
How 3D physics can animate a game in Unity
So what’s the real deal here with this 3D Unity physics?
Well, before a game developer had to write new code each time they needed to change the trajectory of a ball in a video game. Eventually, each new scenario was tiring and time-consuming. Not much fun. Now with Unity’s built-in 3D physics engines, a developer is equipped with some essential components and is able to create true-to-life physical simulations with less time and effort!
This blog reveals some of the core components of Unity 3D physics which assist in making a game in Unity with greater efficiency. The result: the characters and GameObjects act more realistically!
The Main Components of Unity 3D Physics
We can only scratch the surface here, as the list of physics elements is quite extensive. Among some of the main components of Unity 3D physics are a RigidBody and Colliders.
- RigidBody is a must
RigidBody is an essential component that sets up physical interactions between different objects in a video game. For instance, when a RigidBody is attached to a ball, it will react to gravity. Without a RigidBody component, the ball would hang in the midair. If the gravity option is ticked off, your ball will lose its gravity and will fly away into the great unknown of Unity space…
If one would like to use such physical properties as gravitation and inertia, then a RigidBody component has to be attached to a GameObject. Without a RigidBody component, an object can be moved as well, but it won’t have physical properties.
- You can’t do without Colliders
Another important built-in component of Unity physics is Colliders. To put it simply, Colliders are primitive shapes of boxes or spheres. These shapes can be added to objects. It is quite convenient to be able to create a GameObject to which a certain shape can be attributed. On top of that, the shape will follow the object throughout the game.
For instance, a Cube object can be attached to a BoxCollider. Correspondingly a Sphere object will get a SphereCollider. In case of a Cylinder, a CapsuleCollider will be given etc. These Colliders can also be used for any shapes of the user’s geometry not only as simple shapes.
A developer can choose to add Static Colliders to an object that doesn’t have a RigidBody component. Static Colliders are created in Unity 3D game to make such stationary objects as walls, ceilings, etc. NB: it’s highly inefficient to try to move StaticColliders as it forces the physics engine to recalculate the physical properties from scratch again.
The good news is the profiler (the window which helps to optimize a game) will notify a developer if they are dealing with a Static Collider on the warning tab on the CPU Profiler.
Colliders which are added to an object with a RigidBody are called Dynamic Colliders. Static Colliders can intersect with Dynamic Colliders but as they don’t have a RigidBody attached to them, they won’t be moved when encountering collisions. On the contrary, dynamic colliders will move when colliding with other objects as the RigidBody component is added to them.
In Unity games, you have more than one object moving. One object could pass through another object. However, you want to have a 3D game where objects collide bumping into each other!
The Default setting for collision detection is discreet. The Continuous setting is for fast-moving objects that are interacting with static geometry (non-rigid objects). Continuous Dynamic is for fast-moving objects that are interacting with other dynamic objects.
Now let’s move from theory to a practical example and take a look at how 3D physics has been applied to a VR simulator game.
How Unity 3D physics animated our game
Here at Onix, our programmers have developed a tug supply vessel Tug Supply Vessel (AHTS) Ship Simulator App. The app is a virtual reality-based Unity 3D game which offers realistic computer graphics which immerses a player in VR with just a double-click!
Our AHTS motion simulation system was created for entertainment purposes, but a user can learn some principles of navigating the ship as it makes its way overcoming underwater torrents and winds.
The gamer’s task is to steer the ship to the oil rig, avoid traffic, put out any fires using the water guns and keep the vessel within the marked area for 10 seconds. Meanwhile, the gamer is supposed to fight UFOs with water cannons (laser canons are for the weak)!
The player can experience some genuine water physics. The ship is tossed by the sea swells… The squawks of seagulls can be heard in the distance… The ultimate goal is to successfully tie the ship up at an oil-rig and save survivors.
Let’s see how some above-mentioned components of physics were an absolute must in bringing about our game.
No physics, no fun game
To say that physics interaction was very crucial for our VR game is an understatement! Physics, as you’d expect, was hugely important for working on such a simulation game. Our developers used the 2017 version of Unity as the recent releases of the game were not much different in terms of physics.
To put it in simple terms: the interaction between the water and waves is a quite complex system of interactions, where a lot of data has to be taken into account. The important thing that has been achieved was the change of water’s collider in conjunction with the mesh of the water.
The way it works: If the immersion is deeper — the repulsive force is stronger.
Water’s collider has been successfully affected by the repulsive force against the surface of the water.
A physics engine has allowed making the ship move in various directions. The AHTS’ engine pushes the vessel in conjunction with the rotations which are navigable by the engine handle. The mass and the resistance of the water surface had to be taken into account in this respect. Specifically, the physics engine was applied so that the surface of the AHTS and that of the water could interact for a more real on-deck sensation.
On top of that, the ship simulator has been created so that the ship could correspond to the operational force which affected the ship from different sides (i.e. from the water). As we know, waves can slow down the speed of the vessel on the water and even turn it around. These forces had to be taken into account as well.
The AHTS’ motions correspond to the master levers of the ship quite conveniently.
Additionally, different environments can be chosen from numbers 1 (calm) — 5 (heavy storm). The stormy environment gives quite a realistic sensation of the AHTS swayed by the high waves. You will feel as if you are really standing on the deck of the sea vessel! You might even learn if you’ve got a motion sickness.
Furthermore, our GameObjects that interact with the physics have a RigidBody attached to them (i.e. the AHTS, seagulls, UFO, and the captain character). Similarly, the ship’s movement on the water has been created as a RigidBody component. The cups on the table can be lifted up and thrown down on the player’s whim.
Plus, Colliders have been used for regulating the collisions between the objects for each new scene. The force of collisions has been determined by a RigidBody.
Who would want a 3D game without objects bumping into each other as they do in real life? The more real the game, the more real the game experience!
Everybody seems to be loving 3D games these days. Unity has a great engine with a number of built-in physics components that allow creating “real-life” games or simulations.
By implementing Unity 3D physics, our developers have created a VR simulation game where users can experience the game afresh and more realistically.
This might be the prime time for you! Experience the physics in 3D Unity by creating a game in Unity with the help of our team. We can create for you a new VR game experience with some of the coolest physics components. Let your game live!
Great thanks to Vlad Ukraintsev from Onix VR/AR for his insights on the ins and outs on how the Simulator was made.