FORGE3D
  • Welcome
  • FAQ
  • Sci-Fi Effects
    • Getting started
    • Turrets
    • Turret Controller
    • Pool Manager
    • Examples
    • Scripts
    • Changelog
  • Force Field
    • Getting started
    • Force Field Video Tutorial
    • Force Field Controller
    • Rigidbodies
    • Shaders
    • Impact Points
    • Upgrading
    • Platform Differences
    • Changelog
  • Wasp Interdictor
    • VR Setup
    • Controller Components
    • PSD Template
    • Substance Painter Sources
  • Damage FX
    • Shader
    • Controller
    • Colliders
    • Material
    • Debugging damage
    • Impact points
    • Damage FX Shader Node
  • Planets
    • Changelog
Powered by GitBook
On this page
  1. Damage FX

Controller

PreviousShaderNextColliders

Last updated 4 years ago

Assets/FORGE3D/DamageFX/Scripts/DamageFX.cs

In order to control the Damage FX Shader, an instance of the script should be present on each Damage FX Object. The script component handles the data processing for impact spots and fades the heat values over time.

Use DamageFX.Hit() method of the script to add new impacts to the surface of the mesh as shown below:

Here is the simple code snippet that will add the damage point to the Damage FX Object under the mouse cursor on left mouse click:

public float HitRadius = 0.1f; 
public float Dirt = 1f; 
public float Burn = 1f; 
public float Heat = 1f; 
public float Clip = 0.7f;
 
private RaycastHit _hitInfo;
 
private void Update()
{
 
  if (!Input.GetMouseButtonDown(0)) return;
     
  var screenRay = Camera.main.ScreenPointToRay(Input.mousePosition);
   
  if (!Physics.Raycast(screenRay, out _hitInfo, Mathf.Infinity)) return;
   
  var dfx = _hitInfo.collider.GetComponent<DamageFX>();
   
  if (dfx != null) dfx.Hit(dfx.transform.InverseTransformPoint(_hitInfo.point), HitRadius, Dirt, Burn, Heat, Clip);
   
}