Unity. Rigid component

RayFire Rigid component

Its main purpose is Advanced Physics Control and Runtime Demolitions. Using Rigid component you can demolish 3d objects into thousands of fragments and every fragment can be demolished further deeper and deeper.

Initialization: Defines when object will be initialized. Initialization adds all necessary components to object, setup them accordingly to properties, and start necessary coroutines.

  1. By Method: Object will be initialized by Initialize() method. This is the default initialization type. In this way, you can add Rigid component to objects in your code and they will not be initialized unless you will Initialize them as well. Object with ByMethod type can be initialized in Editor using Initialize button on top of Rigid component.
  2. At Start: Object will be initialized at Start.

Object can be initialized using method:
public void Initialize()

   Main

Simulation Type: Defines the behavior of object during simulation.

  1. Dynamic: Object will be affected by gravity, will start to fall down and it will be possible to affect on it by other simulated objects.
  2. Sleeping: Object will freeze in the air until the first collision with any other object, then it will start behaving as Dynamic object.
  3. Inactive: Object will freeze in the air and will not be affected by gravity, it can be affected by other simulated objects but it will not start to fall down until it will be activated. After activation object will start behaving like Dynamic object.
  4. Kinematic: Object will use it’s animation to affect other objects but it will not be affected anyhow by any other object. Can use actual mesh as a collider.
  5. Static: Object will not be moved from its position, it will interact with Dynamic objects but it will not be affected anyhow by any other object. Can use actual mesh as a collider.

***

Object Type: Rigid component can simulate a single object using its mesh for simulation, but also it can simulate multiple objects as one concave object using all children meshes.

  1. Mesh: Simulate object using it’s Meshfilter’s mesh in Mesh Collider.
  2. Mesh Root: Should be added to empty root with children with meshes. Add the same Rigid component to all children and simulate them as Mesh type. Root itself is not going to be simulated. Using this type you don’t need to select every child to add Rigid components or to edit them later, you only need to edit all properties for Root.
  3. Skinned Mesh: Demolishes Skinned mesh object.
  4. Nested Cluster: Simulated object using all it’s children Meshfilter’s meshes as one solid concave object. In this case, the root will get Mesh Collider for every child with its mesh. To Create such object you need to add Rigid component to root which has all objects which you want to simulate as solid object as it’s children. In the case of demolition, Cluster will detach every child and start to simulate them on their own. If the child is also just a root for other children with meshes after demolition it will be considered as Nested Cluster as well. In this way, you can demolish object in your own way.
  5. Connected Cluster: Simulated object using all it’s children Meshfilter’s meshes as one solid concave object like Nested Cluster. It uses only children from the first layer, nesting is not allowed. During demolition, it will detach fragments at the contact point while the rest of the fragments will stay as solid cluster. At every demolition cluster checks itself for connectivity and if it detects that some groups of fragments are not connected together anymore they will start to simulate as separate Connected Clusters.

***

Demolition Type: Define when and how object will be demolished during Play mode.

  1. None: Object will not be demolished.
  2. Runtime: Object will be demolished in Runtime. Fragments will be created at collision contact moment. It is better to use this type for low poly objects with low Fragments Amount value. Slowest speed among other types.
  3. Awake Precache: Object will precache all fragments mesh data in Awake and store all mesh data info in Rigid component. At collision contact, gameobjects with all necessary components will be created and mesh will be assigned.
  4. Awake Prefragment: Object will be prefragmented in Awake. All fragments will be disabled and waiting for demolition.
  5. Manual Prefab Precache: Special type if you want to manually precache mesh data in prefab and save it as asset in project folder. Regular Precache type can not store mesh data as assets because Unity Mesh is not serializable. Precached Prefab stores mesh data in serializable format way which allows to store it as asset.
  6. Manual Precache: Allows to manually precache all fragments meshes in Editor and use precached meshes for fragments. In this case it will not waste time in Awake to cache mesh data for fragments. Do not use this type if you want to create prefab, prefab can not store Unity mesh data, use Manual Prefab Precache instead.
  7. Manual Prefragment: Allows to manually prefragment object in Editor. In this case it will not waste time in Awake to prefragment object.
  8. Reference Demolition: Allows to swap demolished object to predefined reference and demolish instance of this reference instead. The reference object could be FBX asset, prefab, or other scene objects.

 

    Simulation

Physics

Physic Material

Material Type: Material preset with predefined density, friction, elasticity and solidity. Can be edited in Rayfire Man component.

Material: Allows to define define own Physic Material. Keep in mind that it still will use define Material Type for Solidity and Mass.

Mass

Mass By: Allows to choose the way Mass will be applied to RigidBody component.

  1. Material Density: Object will get mass accordingly to defined Material Type and mesh volume.
  2. Mass Property: Object will get mass by Mass property.

Mass: RigidBody component will get this value if Mass By set to Mass Property.

Collider

Collider Type: Allows to choose automatic collider type for object if object has no custom collider applied.

  1. Mesh: Object will get Mesh Collider.
  2. Sphere: Object will Sphere Collider
  3. Box: Object will get Box Collider.
  4. None: Object will not get automatic collider.

Activation

Inactive object can be activated using public method:
public void Activate()

By Velocity: Inactive object will be activated when it’s velocity will be higher than By Velocity value when it was pushed by other dynamic objects. Turned Off when set to 0.

By Offset: Inactive object will be activated if will be pushed from it’s original position farther than By Offset value. Turned Off when set to 0.

By Damage: Inactive object will be activated if it’s Current Damage will be higher than By Damage value. Turned Off when set to 0.

By Activator: Inactive object will be activated by overlapping with object with RayFire Activator component.

By Impact: Inactive object will be activated when it will be shot by RayFire Gun component.

By Connectivity: Inactive object will be activated if it won’t be able to reach any Inactive object with Unyielding property On through other Inactive objects. RayFire Connectivity components has to be used to establish connectivity between Inactive objects and activate them if they loose connection with other Inactive objects.

Unyielding: Allows to define Inactive object as Unyielding to activate other Inactive objects with enabled By Connectivity activation type.

 

    Demolition

Demolition can be initiated using method:
public void DemolishObject()

Slicing by planes can be initiated by method:
public void AddSlicePlane(Vector3[] slicePlane)
Vector3[] slicePlane is array with slicing planes info:
(plane position, plane normal, plane position, plane normal, etc…)

Limitations

Solidity: Local Object solidity multiplier for object. Low Solidity makes object more fragile. Keep in mind that every Material Type in Physics group also has it’s own Solidity. Set to 0 if you want object to be demolished at first contact.

Depth: Defines how deep object can be demolished. Depth is limitless if set to 0.
Example: Max Depth set to 1, it means that object can be demolished one time and new fragments (Depth level 1 fragments) will not be possible to demolish anymore.
If Max Depth set to 2, it means that object can be demolished one time and new fragments (Depth level 1 fragments) will possible to demolish one time, but new fragments (Depth level 2 fragments) will not be possible to demolish anymore. Etc

Time: Safe time. Measures in seconds and allows to prevent fragments from being demolished right after they were just initialized.
Example: Time set to 3 seconds, it means that object can be demolished and new fragments will not be demolished for sure during next 3 seconds.

Size: Prevent objects with bounding box size less than defined value to be demolished. Measures in units.

Slice by Blade: Allows object to be sliced by object with RayFire Blade component.

Mesh Demolition

Fragments

Amount: Defines amount of new fragments after demolition.

Variation: Defines additional amount variation for object in percents. Final amount always will be higher than Amount value.
Example: Amount set to 50, Variation set to 10 %. Final amount will be randomly picked in range from 50 to 55.

Depth Fade: Amount multiplier for next Depth level. Allows to decrease fragments amount of every next demolition level.
Example: Amount set to 100. Depth Fade set to 0.5. Object demolishes to 100 fragments. For every fragment it’s Amount for next demolition will be set to 50 (100 * 0.5). Let’s say some fragment demolishes to 50 fragments. For every fragment among these 50 fragments it’s Amount for next demolition will be set to 25 (50 * 0.5).

Contact Bias: Higher value allows to create more tiny fragments closer to collision contact point and bigger fragments far from it. This is the property which makes player understand that Runtime demolition happened right now and nothing was prefragmented before.

Seed: Defines Seed for fragmentation algorithm. Same Seed will produce the same fragments for same object every time.

Use Shatter: Allows to use RayFire Shatter properties for fragmentation. Works only if the object has RayFire Shatter component. This is the only way to create other Fragmentation types in runtime because the default demolition fragmentation type produces only regular Voronoi fragments.

Advanced Properties

Collider

Collider Type: Defines Collider type for mesh fragments if they bounding box size is less than Size Filter value. Useful in case you want to apply simple colliders for a lot of small fragments.

Size Filter: Defines Bounding Box size value for Collider Type property. Turned Off if set to 0.

Mesh Ops

Decompose: Decompose output fragment’s mesh to several meshes if they are not connected with each other.

Remove Collinear: Remove collinear vertices on output fragment’s mesh.

Custom Layer

Layer: Set custom Layer to fragments.

Runtime Caching

Type: Defines Runtime Caching type. Disabled by default.

  1. By Frames: Cache fragment’s meshes over a defined amount of frames.
  2. By Fragments per Frame: Cache defined amount of fragment’s meshes every frame.

Frames: Defines the amount of frames for By Frames type.

Fragments: Defines the amount of fragments for By Fragments per Frame type.

Skip First Demolition: Do not demolish object when all meshes were cached and wait for the next demolition. Allows to use the first Demolition to initiate caching and demolish object only at second demolition.

Mesh Input

Cluster Demolition

Properties

Mesh Demolition: Set Runtime demolition type for extracted fragments.

Connected Cluster

Connectivity: Defines the Connectivity algorithm for clusters.

  1. By Bounding Box: Fast but not accurate. Check for connectivity using object’s bound boxes. Can be used with any kind of object.
  2. By Mesh: Slow but accurate. Check for connectivity using the object’s mesh. Can be used only with fragments which share the same triangles (Voronoi, Slabs, Splinters, and Radial fragmentation types).

Contact Radius: Defines distance from contact point in percentage relative to the object’s size which will be detached at contact.

 

Reference Demolition

Source

Reference: Defines reference for demolition. Reference will be instantiated and demolished instead of the original object.

Random List: Allows to define several references and pick for demolition one random.

Properties

Add Rigid: All references without Rigid Component will get it automatically. Single Object will get Mesh Object Type, Roots with a group of mesh objects will get Mesh Root object type.

 

Material

Inner surface

Inner material: Defines material for fragment’s inner surface. If not applied RayFire will use original object material for the inner surface.

Mapping Scale: Defines the mapping scale for inner surface. Using this property you can increase or decrease the size of texture for the inner surface.

Outer surface

Outer material: Defines material for fragments.

Damage

Enable: Allows to demolish object by it’s own floating Damage value. Object will be demolished when Current Damage value will be more or equal Max Damage value. Current Damage value can be increased by RayFireBomb and RayFireGun components, by Collision or by public method:

public bool ApplyDamage(float damageValue, Vector3 damagePosition)

damagePosition: Position in world space. In this case damage position will be used by Contact Bias to create more tiny fragments at damaged area.
True boolean return value means than object was demolished because of applied damage.

Max Damage: Defines maximum allowed damage for the object before it will be demolished.

Current Damage: Shows current damage value.

 

Collisions

Collect: Allows to accumulate damage value by collisions during dynamic simulation.

Multiplier: Multiply collected collision damage.

Fading

Fade Type: Fading lets you keep your scene clean and optimize dynamic simulation by destroying fragments or excluding them from the simulation.

  1. None: Fragments will stay in scene with no limitation and they always will be simulated.
  2. Sim Exclude: Fragments will be simulated for Life Time period after their birth, then their Colliders and RigidBody components will be destroyed.
  3. Move Down: Fragments will be simulated for Life Time period after their birth, then they will fall through the ground and will be destroyed after Fade Time period.
  4. Scale Down: Fragments will be simulated for Life Time period after their birth, then they will start slowly scaling to nothing during Fade Time period and destroyed after all.
  5. Destroy: Fragments will be simulated for Life Time period after their birth and destroyed instantly.

Size Filter: Prevent object for fading if it’s size bigger than defined value. Turned Off if 0.

Life Time: Minimum period of time in seconds during which fragments created by demolition or slicing will be simulated.

Life Variation: Add random period of time in seconds to final Life Time.

Fade Time: Period of time in seconds during which object slowly moves through the ground or scales down to nothing.

 

Events

RayFire Rigid component provides subscription to Demolition and Activation events.

Subscription to Global event will invoke subscribed method when any demolition happens.

Global Demolition event subscription reference:
RFDemolitionEvent.GlobalEvent += MyMethod;

Global Activation event subscription reference:
RFActivationEvent.GlobalEvent += MyMethod;

Subscription to Local event will invoke subscribed method when demolition of specific Rigid script happens and because of this you need to have reference to Rigid component you want to track.

Local Demolition event subscription reference:
GameObject myGameObject = GameObject.Find(“MyObjectWithRigidComponent”);
RayfireRigid rigid = myGameObject.GetComponent<RayfireRigid>();
rigid.demolitionEvent.LocalEvent += MyMethod;

Local Activation event subscription reference:
GameObject myGameObject = GameObject.Find(“MyObjectWithRigidComponent”);
RayfireRigid rigid = myGameObject.GetComponent<RayfireRigid>();
rigid.activationEvent.LocalEvent += MyMethod;

Keep in mind that MyMethod should have RayFireRigid component as input, in this way you can get access to all public variables of Rigid component, for instance:
void MyMethod(RayfireRigid rigid)
{
Debug.Log(rigid.fragments.Count);
}
will show in console amount of fragments which were created as a result of demolition.