Table of Contents

This lesson focuses on teaching the basics of physics effects and components.

Learning Objectives

  • GravityEffect and DragEffect components
  • Apply / Ignore physics effects on objects
  • Basic uses of name=LevelSettings, icon=cog

Level Setup

FallingSquare

GravityEffect

When running the game, we can see the square object falling. As we mentioned in previous tutorials, the RigidBody component allows an object to be subjected by physics forces. However, it is not the one responsible for the object falling.

Let's take a look at the LevelSettings object in our level:

  • In the Objects window
  • Select : LevelSettings object

image

image

Common GravityEffect Properties
Active checkBox Whether this component applies force or not
Strength The magnitude of the force applied
Direction The direction which force is applied (normalized)
LocalSpaceDirection checkBox Whether the specified direction is local (true) or global (false)

image

Notice that the Sprite object isn't being affected by gravity anymore. That's because components that produce physics effects, when attached to the LevelSettings object object, will apply that effect to all objects within the Space.

Let's try and move the Sprite object in other ways:

SlowingSquare

The Sprite object appears to be moving in the desired direction and still isn't affected by gravity but it slowed down and stopped. But according to Newton's first law of motion; an object retains its movement at a constant velocity unless acted upon by an external force. So what external force caused our object to stop?

DragEffect

Let's take a look again at the LevelSettings object:

  • Select : LevelSettings object
  • In the Properties Window
  • Under DragEffect image
    • Set Active checkBox to false
Common DragEffect Properties
Active checkBox Whether this component applies force or not
LinearDamping The amount of damping applied to the object's velocity
AngularDamping The amount of damping applied to the object's angular velocity

EverMovingSquare

The DragEffect exists to simulate air resistance and other forces that would prevent your object from moving indefinitely.

Adding Physics Effects to Objects

These effects can also be applied to individual objects, let's take a look:

FallingSquare

Now we get the same result we had initially, but we could tweak individual gravity and drag effects per object.

WARNING: GravityEffect (and some other PhysicsEffects) have the LocalSpaceDirection checkBox property set to true by default. This means that, as the object rotates, the "down direction" will be constantly changing. Set LocalSpaceDirection checkBox to false to avoid this behavior.

TumblingSquare

IgnoreSpaceEffects

Lastly, let's say you wanted all objects in your level to be affected by gravity except for a few. You could turn off the GravityEffect on LevelSettings object and add a GravityEffect component to every object that needs it but that would be a lot of work.

Alternatively, you could leave the GravityEffect on LevelSettings object on and just add the IgnoreSpaceEffects component to the objects that you don't want gravity on:

image

NOTE: The IgnoreSpaceEffects component will only stop physics effects attached to LevelSettings object or Space to affect the object; if the object has a GravityEffect component or any other physics effects components on itself, they will not be ignored!

Region

The region component can be used to apply any physics effects (Gravity, Drag, etc) to a specific zone. It works by using a Collider (which it has a dependency on) as a trigger volume to determine whether objects are inside it and then applies the specified force effects.

NOTE: Experiment by adding the ForceEffect , BuoyancyEffect and WindEffect

Related Materials

Manual

Code Reference

Classes

Commands