Unreal Physics System: Learning the Essentials in 10 Minutes

Introduction

Unreal’s real-time physics body system is quite powerful, using physics it is easy to add fun and organic animation to your project, (also as a non-animator, I don’t have to hand key anything) which is why I just love it.

Today I want to show you a basic example that you can create within 10 minutes as an introductory to Unreal’s physics system. Afterward, you’ll be able to create many physics mechanic using the principle we learned today.

Here’s the final result we’re creating: a dynamic jump bad that bounces object off, then return to original position.

jump pad

Physics Body and Constraints

Generally speaking we need at least one physics body (two in our case) and an physics constraints to build a dynamic mechanic system.

outline

  • Physics body: contains the physics attribute of the object, usually mass, center of gravity, collision shape, physics material (how it reacts to surface) and etc

  • Physics constraints: dictate the movement of the physics object/body.

To create physics body, is quite easy, we add static meshes and check “Simulate Physics”,

To create a physics constraint there must be two component specified, we can have many constrains, but each constraint tell Unreal the relationship between the two physics body. (we only need one in our example, which is the relationship between our pad and our base)

  • Component 1 (Pad): is the “child” component of the two, the one with simulated physics turned on

  • Component 2 (Base): is the “parent” component of the two, our base is static, which means you can also leave this component as “None” which will default as the scene root

constraint

Disabled collision in the physics constraint should be enabled if possible to avoid collision between the two simulated component

Constraint Limits

The movement limits is one of the most important attribute of our system. There are two types of constraint limits: linear and angular.

Axes: Usually if you want the movement on certain axes either rotation or translation toggle on free (unrestricted) or limited motion (restricted within certain range), if you don’t want any movement at certain axes you would specify it to be locked

linear

For our jump pad example, we would like to limit our translation movement to be up and down, so we locked the X and Y motion.

angular

We would like our jump pad to swing sideways but no twisting motion, which is why we locked the twist motion axis (the naming can be confusing sometime)

What is good is that unreal provides this gizmo which you can easily tell if you have the correct range of motion setup.

gizmo

Soft Constraint

Movement Range: Limited motion allows you to specify a limit range also enabling you to turn on soft constraint

The soft constraint being soft means that you can also tweak the stiffness and the damping of the soft constraint to mimic a spring behavior

  • There’s also an angular breakable or linear breakable which can be helpful to break the constraint when the force reached a certain threshold

Motor

A simulated body with no reaction will appear very boring, because it will basic rest eventually.

That’s where motor are introduced, this can be used in example such as a revolving door that rotates infinitely, a seesaw that returns to its neutral balanced position, and in our case, after our jump pad launches, it will snap back to its initial position.

Another example usage of motor is to create a resilient resistances internal force that fights back the external force. In our case the bouncing springy motion when an external heavy object is dropped on our jump pad.

I will explain the linear and angular motor together as they have the same principle:

Target Position/Orientation:

The settling position/orientation that the constraint will try to make our physics body rest at, the strength is how much the motor forces to drive the simulated component back to the target (i.e. how much this is enforced by our motor)

  • The target position/orientation should be kept at zero if the initial position is the desired rest position.

Velocity Target:

The settling velocity that the constraint will try to maintain on our physics body, the strength is the same as before.

For angular motor: the drives should match the movement along certain axes

  • The target velocity should be kept at zero if we want the physics body to stay still (0 velocity) at the end.

Note and Tips

  • The motor force is determined by both the strength and multiply the mass/weight of the simulated component. The heavier the object, the more strength you’ll need

  • The target velocity kept at zero (means the constraint will try to cancel out any velocity) with a small strength can help reduce the wobbliness caused by the motor fighting the gravity.

  • A target velocity only (meaning no target position/rotation), this will be able to apply a continuous movement/velocity to keep it moving, good for infinite rotating door

motor

BP Access

Example: Not starting with non-neutral position

Let’s consider an initial pulled back springboard that will return to neutral position.

In order to achieve this effect, we need to pull the simulated component in the viewport and apply the counter offset value which will put the component back to neutral

if the neutral is (0, 0, 120), and pull back is (0, 0, 60)

Steps:

  1. in the viewport set it to (0, 0, 60)
  2. then in the linear motor set it to (0, 0, -60)
    • -60 comes from subtracting 60 with 120
  3. this will make the springboard launch to the neutral position when starting as pulled back

bp

This can be done in blueprint via set linear position target on the constraint.

  • you can also use this BP node to dynamically change the target, for instance you need to make a radial switch level that can flip-flop between 2 target state, or a seesaw that bouncing back and forth infinitely.

Other Notes

  • To save compute power, Unreal will put physics object to sleep if it’s not moving, we need to specify “sleep velocity threshold” or make use of the “Wake Rigid Body” function call in BP to make our physics object operating as normal

  • The base can be hidden or set to not visible, but it has to exist because the physics constraint needs two components to work you can also disable collision on the base by setting the collision preset to query only and ignore everything

References

Everything in this guy’s YouTube channel is gold: YouTube - Lusiogenic