Namespace: MDPackage.Modifiers
Damage/ distort physical mesh by specific parameters.
Read more here (Online documentation slide)
Public Methods
public void MeshDamage_ModifyMesh(Vector3 point, float radius, float force, Vector3 direction, bool continuousEffect = false)
public void MeshDamage_RefreshVertices()
public void MeshDamage_RestoreMesh(float restorationSpeed = 0.1f)
public void MeshDamage_ModifyMesh(MDM_RaycastEvent RayEvent)
Public Fields
public bool detectForceImpact = true;
public float forceAmount = 0.15f;
public float forceMultiplier = 0.075f;
public bool detectRadiusSize = false;
public float radius = 0.5f;
public float radiusMultiplier = 1.0f;
public float radiusSoftness = 1.0f;
public float forceDetection = 1.5f;
public bool continousDamage = false;
public bool collisionWithSpecificTag = false;
public string collisionTag = "";
public bool enableEvent;
public UnityEvent eventOnDamage;
Examples
The following paragraphs contain Mesh Damage modifier component used in a practical example - damage specific mesh with raycast at runtime.
using UnityEngine;
using MDPackage.Modifiers;
[RequireComponent(typeof(MeshFilter))]
public class SampleScript : MonoBehaviour
{
public Camera mainCam;
[Space]
public float damageRadius = 0.25f;
public float damageForce = 0.5f;
public bool continuousEffect = true;
private MDM_MeshDamage damageable;
private void Start()
{
damageable = MD_ModifierBase.CreateModifier<MDM_MeshDamage>(gameObject, MD_ModifierBase.MeshReferenceType.CreateNewReference);
damageable.gameObject.AddComponent<MDPackage.MD_MeshColliderRefresher>();
}
private void Update()
{
if (!mainCam)
return;
if (Input.GetKey(KeyCode.R))
damageable.MeshDamage_RestoreMesh(0.01f);
if (Input.GetMouseButtonDown(0))
{
Ray r = mainCam.ScreenPointToRay(Input.mousePosition);
bool hit = Physics.Raycast(r, out RaycastHit h) && h.transform == damageable.transform;
if (hit)
damageable.MeshDamage_ModifyMesh(h.point, Mathf.Abs(damageRadius), -Mathf.Abs(damageForce), h.normal, continuousEffect);
}
}
}