Table of Contents

This lecture covers the basic usage of PhysicsMaterials and the MassOverride component.

Learning Objectives

  • Creating and applying PhysicsMaterials
  • Basic physics concepts (Mass, Volume, Density, Restitution and Friction)
  • Using the MassOverride component

Level Setup

CollidingSquares

Mass

In Zilch Engine, any object with a RigidBody is automatically assigned mass. An object's mass represents its weight and is determined by its Volume and Density (M = D * V). Volume is calculated from a combination of the Collider type along with its size defining properties and the object's scale, while its Density is defined by the object's PhysicsMaterial. By altering these properties we can manipulate how objects interact physically with each other.

NOTE: An object with RigidBody but with no Collider will be assigned a mass of 1 while an object with a Collider but no RigidBody can be thought of as having infinite mass.

In our constructed scenario so far we see two objects colliding with each other in a space with no gravity or drag. A quick look on each object's RigidBody component shows the current Mass . Since both objects have the same physics properties (mass, restitution, velocity magnitude, etc) we conclude that the collision is symmetric and both objects apply an equal force to each other when they collide.

Volume

Let's explore what happens when we give them different Volumes:

CollidingSquaresMass1

Since we've made the object bigger, its mass has also increased which we can verify by checking the RigidBody on RedSquare object. We can observe that the more massive object imparts a larger force onto the smaller object than the smaller does to it.

In the next section, we'll explore tweaking an object mass by altering its density.

Density

DensePhysMat

  • In the Library Window
  • Under PhysicsMaterial
  • Double-Click Dense resource
  • In the Properties Window
  • Set Density to 8

image

  • Select : RedSquare object
  • In the Properties Window
  • Under Transform
  • Set Scale back to [1, 1, 1]
  • Under BoxCollider
  • Set Material resource to Dense

DenseCollision

Similar to the previous case, the more massive object imparts a greater force despite both objects having the same volume. Lastly, let's look into another way of setting an object's mass.

MassOverride

The MassOverride component allows you to set an object's mass regardless of its Volume or Density. It has a dependency on RigidBody.

image

MassOverride Properties
Active checkBox Whether this component is currently overriding the RigidBody's mass
Mass The value RigidBody's mass is being overrided by)
RecomputeMass Recalculates and sets MassOverride's mass property to the default value

CollidingSquares

In adding the MassOverride component, we just reset the RedSquare object's mass to 1 despite it still having the Dense resource PhysicsMaterial

Restitution

Another useful feature of PhysicsMaterial is Restitution: a value that represents the object's bounciness. It is represented by a value from 0 to 1 and denotes how much of its energy is preserved after the collision (0 being no energy preserved and 1 being 100% of energy preserved). You may also set Restitution to a value greater than 1 (by right-clicking the field) to cause the object to bounce away with greater energy.

  • Command : Add Resource

  • Create a PhysicsMaterial named Bouncy

  • In the Library Window

  • Under PhysicsMaterial resource

  • Double-Click Bouncy resource

  • In the Property Window

  • Set Restitution to 1

  • Set RestitutionImportance to 1

  • Add Resource

  • Create a PhysicsMaterial named NotBouncy

  • In the Library Window

  • Under PhysicsMaterial resource

  • Double-Click the NotBouncy resource resource

  • In the Property Window

  • Set Restitution to 0

  • Set RestitutionImportance to 1

  • Select : BlueSquare resource

  • In the Properties Window

  • Remove Component : RigidBody

  • Under BoxCollider

  • Experiment by setting PhysicsMaterial enum to Bouncy and NotBouncy

  • Command : PlayGame

Bouncy NotBouncy

Friction

Friction is a coefficient that represents how much energy is lost when objects slide against one another. Each PhysicsMaterial provides a friction value and their combination will determine the friction force used for the collision between the two objects. The higher the friction value, the more energy will be lost per frame except when either object has a friction value of 0, in which case no energy will be lost.

NOTE: Similar to the case with restitution, PhysicsMaterials have a FrictionImportance property, which determines which object's Friction value to use in a collision.

Friction

Related Materials

Manual

Reference

Classes

Commands

Development Tasks

  • T2562
  • T141