Getting started

The easiest way to understand the basics is to create your first Force Field object. Let’s get started with a new scene and a few things to help us along. We will use one object to render the shield effect and the other to render a surface it covers.

Creating geometry

  • Create sphere from Unity menu GameObject -> Create Other -> Sphere and place it in front of the camera

  • Duplicate the Sphere game object using Edit -> Duplicate menu and rename it to “Shield“. Select Sphere game object and remove Sphere Collider component.

Adding a controller

Next thing required is a controller script. Let’s add one to the Shield and assign the game object reference to be used as a shield surface.

  • Add Forcefield.cs script component to the Shield game object using the inspector’s “Add Component” either manually from Assets/FORGE3D/Force Field/Scripts folder by dragging it on top.

  • Select Shield game object in the Hierarchy panel and drag it on top of the empty ‘Field‘ property of the Force Field Controller within the Inspector.

Adding a material

It’s time to create a new material and assign it to the Shield. We will use Force Field shader to render the shield and the corresponding effects.

  • Create new Material in Project panel: Right Click -> Create -> Material and name it “Shield“.

  • Select the material and pick FORGE3D/Force Field/Force Field shader from the drop down list.

Shader setup

Force Field ships with a set of textures to help you create various kinds of shield effects. In this chapter, we will set the shield, its colors, and different properties so it looks and feels the way it should.

  • Plug the texture mask into the Field Texture slot, such as “field_charge_003“, which can be found under the Assets/FORGE3D/Force Field/Textures path, and set the texture tiling to 8 on X and 4 on Y to help the spherical shield appear in a more pleasant way.

Next important step is to set up a shield color gradient with help of both Inner and Outer Masks Tints. Note the alpha value is used to boost the multiplier, and it is vital to get it shine with your juicy Glow Image Effect.

  • Set ‘Inner Mask Tint‘ RGBA color values to (R: 130, G: 220, B: 255, A: 40 / HEX Color #82DCE128)

  • Set ‘Outer Mask Tint‘ RGBA color values to (R: 0, G: 150, B: 255, A: 40 / HEX Color #0096FF28

The “Mesh Offset” will push the shield along its normals and the “Pan Speed” will animate the texture so you shield looks more like alive. So leave the positive default values as it is more than enough for our purpose.

Now it’s time to set shield feedback at the moment of impact. “Background Visibility” is the first layer that makes the effect.

  • Set “Field Background Visibility” value to 2

Sparks” are the eye candy which makes texture masks shine at the moment of its intersection. Let’s set it’s visibility as well:

  • Set “Field Sparks Visibility” value to 3

Inner Mask” will flash first at the point of impact and will fade inwards by the speed of the “Decay” parameter controlled from the Force Field script. “Offset” specifies the size of the original mask where higher values will make the mask appear smaller due to POW function.

  • Set “Inner Mask Offset” value to 8

  • Set “Inner Mask Feather” value to 8

Feather” controls how smooth the mask should be drawn. Let us set some values to get the hang of it before diving into much of the technical details. The additional “Outer Mask” will reveal at the impact point spreading outwards and forming a “blast wave” effect:

  • Set “Outer Mask Offset” value to 4

  • Set “Outer Mask Feather” value to 4

Triggering the shield

Last chapter concluded the shield set up and it is about time to wreck the havoc on the field. The Force Field controller you have attached earlier will handle such task of assuring the shield reacts accordingly to the damage dealt.

To simplify things, you will use a SimlpeGun.Cs that simulates the projectile cast from camera’s screen point beneath your mouse cursor.

  • Attach the SimpleGun.Cs script to the camera. You will also find it located under the Assets/FORGE3D/Force Field/Examples/Scripts folder.

Blast it!

We went through the process of a shield assembly from scratch, and now everything is ready to launch into the game mode and trigger the shield.

  • Hit Play within the editor and click and hold the Left Mouse Button on top of the sphere.