Book Image

Unreal Engine Physics Essentials

By : Devin Sherry, Vladimir Alyamkin, Katax Emperore
Book Image

Unreal Engine Physics Essentials

By: Devin Sherry, Vladimir Alyamkin, Katax Emperore

Overview of this book

This book gives readers practical insight into the mathematical and physics principles necessary to properly implement physics within Unreal Engine 4. Discover how to manipulate physics within Unreal Engine 4 by learning basic real-world mathematical and physics concepts that assist in the implementation of physics-based objects in your game world. Then, you'll be introduced to PhAT (Physics Asset Tool) within Unreal Engine 4 to learn more about developing game physics objects for your game world. Next, dive into Unreal Engine 4’s collision generation, physical materials, blueprints, constraints, and more to get hands-on experience with the tools provided by Epic to create real-world physics in Unreal Engine 4. Lastly, you will create a working Vehicle Blueprint that uses all the concepts covered in this book, as well as covering advanced physics-based topics.
Table of Contents (15 chapters)
Unreal Engine Physics Essentials
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Preface
Index

Newton's laws/Newtonian physics concepts


The base of all that we know about real-world physics comes from the principles developed by Sir Isaac Newton, also known as Newton's three laws of motion. When we recreate real-world physics in video games, it is very important that we understand these laws and how they affect objects in our game world. Keep in mind that not all games use realistic physics, but these laws of motion are still important to grasp when you develop any game world.

Newton's first law of motion

Isaac Newton's first law of motion, also known as the Law of Inertia, states that every object in a state of uniform motion tends to remain in that state of motion unless an external force is applied to it. In other words, an object in motion tends to stay in motion unless acted upon by another force.

In the real world, there are external forces (such as ground and air friction) that act on objects in motion that eventually cause this object to stop completely, or forces such as a person pushing or pulling on an object that can cause acceleration, or for the move to increase in speed over time. In a vacuum, there is no friction. As a result, an object in motion in an infinite vacuum space would continue to move at the same rate unless it is acted on by some external force.

In Unreal Engine 4, the blueprint assets that utilize the Projectile component, such as bullets, rockets, or any other kind of projectiles used in our game, can edit the coefficient of friction and other physics-based properties. From the first person project that was created earlier in the chapter, we can navigate to the Content folder in the Content Browser and then to the FirstPersonBP folder and select the Blueprints folder. In this folder, we can select the FirstPersonProjectile blueprint. Then, in the Viewport, we can select the Projectile component to view some of the physics properties, as shown in the following screenshot:

By increasing the Friction property, we can cause this projectile to come to a stop more quickly, whereas decreasing this property will result in the projectile coming to a stop over a longer period of time. We can alter this property until we can get the behavior we want. For more examples of physics-based properties featured in the Unreal Engine 4 blueprints, feel free to investigate the FirstPersonCharacter blueprint and select the CharacterMovement component.

Newton's second law of motion

This states that the relationship between an object's mass (m), its acceleration (a), and the applied force (F) is F = ma or an applied force is equivalent to the mass of the object and its applied acceleration. Acceleration and force are vectors, (remember that a vector is both a numerical value and a direction). In this law, the directional force vector is the same as the direction of the acceleration vector.

In more simple words, this law focuses on the principle that a change in an object's velocity can only occur if this object is accelerating in a particular direction, and a positive or negative acceleration can only take place if an external force is acting on it.

In Unreal Engine 4, we can use blueprints to apply forces to physics objects and override properties (such as acceleration and mass) through different available components. For example, the CharacterMovement component in the FirstPersonCharacter blueprint has a property labeled as Max Acceleration, and if we increase or decrease this property, we can see how quickly the player accelerates from a stationary position to its maximum walk speed.

Newton's third law of motion

Isaac Newton's third law of motion and one of the more commonly known law states that for every action there is an equal and opposite reaction. In other words, when an object applies force to another object, an equal and opposite force is applied as well.

In Unreal Engine 4, we can see this law of motion in action by playing in the editor and clicking on the left mouse button while aiming at the ground to see the ball bounce in the opposite direction that it was fired at and moving at a speed equal to the one in which it was fired at, except that we have friction applied to this projectile, so it loses some of its initial velocity due to the friction.

To bring all of these laws of motion together, what we can do is add a box collision component to the FirstPersonCharacter blueprint, set its Collision Presets to BlockAll, and attach it to the FirstPersonCamera component by dragging it onto the FirstPersonCamera component in the Components tab.

Now if we play in the editor, we can start running into the physics cubes in the FirstPersonExampleMap (which is default to the First Person project template) and see forces applied to them, which is equal to the mass of the player multiplied by the players' current acceleration value.