0
Answered

fracturing & Destruction

System Stack 3 years ago updated by Lazlo Bonin (Lead Developer) 3 years ago 3

Hi,


I saw in your Chronos trailer (which as many have said is absolutely art, its beautiful) you explode some structures and then rewind them.

I have Fracturing and Destruction but my coding skills are zero.

Would I be able to use Chronos with my Fractures, do you utilise a specific method in Chronos?

If I was to purchase Chronos would I be able to get my fractures working well enough by examples and youtube? are there any working example of code you could provide me to learn from?

Chronos Version:
Unity Version:

Answer

+1
Answer
Completed

Hello,


I'm moving this to a public topic in case other users have the same question.


Here is the fully commented class I used to make the explosion with Fracturing & Destruction + Chronos in the YouTube video.


using UnityEngine;using System.Collections;
using System.Collections.Generic;
using Chronos;

public class Missile : BaseBehaviour
{
    void OnCollisionEnter(Collision collision)
    {
        // The contact point is a bit below the ground -- makes for more dramatic explosions.
        Vector3 contact = collision.contacts[0].point + Vector3.down * 3;

        // The missile will target everything in a 20 units radius
        float range = 20;

        // And apply an explosion force of 80 units
        float force = 80;

        // Find the physical objects in range
        Collider[] nearby = Physics.OverlapSphere(contact, range);

        // Loop through them to find which one are FracturedChunks in FracturedObjects (fragments of the whole in the plugin)
        HashSet<FracturedObject> fracturedObjects = new HashSet<FracturedObject>();
        foreach (Collider collider in nearby)
        {
            FracturedChunk chunk = collider.GetComponent<FracturedChunk>();

            if (chunk != null)
            {
                fracturedObjects.Add(chunk.GetComponentInParent<FracturedObject>());
            }
        }

        // Loop through the FracturedObjects
        foreach (FracturedObject fracturedObject in fracturedObjects)
        {
            // Make sure it hasn't already exploded
            if (fracturedObject != null && fracturedObject.isActiveAndEnabled)
            {
                // Loop through each chunk of the FracturedObject
                foreach (FracturedChunk chunk in fracturedObject.GetComponentsInChildren<FracturedChunk>())
                {
                    // Add a Timeline (Chronos) to the chunk if it doesn't already have one
                    Timeline chunkTimeline = chunk.GetComponent<Timeline>();
                    if (chunkTimeline == null)
                    {
                        chunkTimeline = chunk.gameObject.AddComponent<Timeline>(); // Add the Timeline...
                        chunkTimeline.mode = TimelineMode.Global; // ... watching the global clock...
                        chunkTimeline.globalClockKey = "Root"; // ... called "Root".
                        chunkTimeline.rewindable = true; // ... and make it rewindable
                    }

                    // Add a TimeColor (custom class to color the object by its time scale, as seen in the video)
                    // You can find a similar class in the Chronos examples folder
                    TimeColor chunkTimeColor = chunk.GetComponent<TimeColor>();
                    if (chunkTimeColor == null)
                    {
                        // Ignore roads, tracks, bridges, etc.
                        if (!chunk.name.Contains("Track") && !chunk.name.Contains("Road") && !chunk.name.Contains("Bridge"))
                        {
                            chunkTimeColor = chunk.gameObject.AddComponent<TimeColor>();
                        }
                    }
                }

                // Explode the object (plugin method)
                // It's important to notice that we have to manually multiply by time.timeScale here
                // because the plugin's source doesn't use Chronos' PhysicsTimer methods, of course.
                fracturedObject.Explode(contact, force * time.timeScale);
            }
        }
    }
}

Hello,


Just so you know I am not being lazy, I have done some 'homework'

I see that you actually used Fracturing Destruction also in your trailer (nice....)

I have read through the forum and looked at the migration tables you have (very good)

The thing for me is that, before I spend the money I want to be sure that I can achieve what I need.

Are you able to provide an example of how Chronos would work with one of the Fracturing demos like floor exploding, or the sphere dropping onto the other? what needs to be changed or added to the chunks or main fracture scripts?

My coding skills are not good I can only work by example I can change all the time.deltaTime instances of course.But I am worried that your first instruction like 'make the non-static component public' will go over my head.

I'm really looking forward to acquiring Chronos if I can manage to create time control effects with the Fracturing asset

Many thanks

+1
Answer
Completed

Hello,


I'm moving this to a public topic in case other users have the same question.


Here is the fully commented class I used to make the explosion with Fracturing & Destruction + Chronos in the YouTube video.


using UnityEngine;using System.Collections;
using System.Collections.Generic;
using Chronos;

public class Missile : BaseBehaviour
{
    void OnCollisionEnter(Collision collision)
    {
        // The contact point is a bit below the ground -- makes for more dramatic explosions.
        Vector3 contact = collision.contacts[0].point + Vector3.down * 3;

        // The missile will target everything in a 20 units radius
        float range = 20;

        // And apply an explosion force of 80 units
        float force = 80;

        // Find the physical objects in range
        Collider[] nearby = Physics.OverlapSphere(contact, range);

        // Loop through them to find which one are FracturedChunks in FracturedObjects (fragments of the whole in the plugin)
        HashSet<FracturedObject> fracturedObjects = new HashSet<FracturedObject>();
        foreach (Collider collider in nearby)
        {
            FracturedChunk chunk = collider.GetComponent<FracturedChunk>();

            if (chunk != null)
            {
                fracturedObjects.Add(chunk.GetComponentInParent<FracturedObject>());
            }
        }

        // Loop through the FracturedObjects
        foreach (FracturedObject fracturedObject in fracturedObjects)
        {
            // Make sure it hasn't already exploded
            if (fracturedObject != null && fracturedObject.isActiveAndEnabled)
            {
                // Loop through each chunk of the FracturedObject
                foreach (FracturedChunk chunk in fracturedObject.GetComponentsInChildren<FracturedChunk>())
                {
                    // Add a Timeline (Chronos) to the chunk if it doesn't already have one
                    Timeline chunkTimeline = chunk.GetComponent<Timeline>();
                    if (chunkTimeline == null)
                    {
                        chunkTimeline = chunk.gameObject.AddComponent<Timeline>(); // Add the Timeline...
                        chunkTimeline.mode = TimelineMode.Global; // ... watching the global clock...
                        chunkTimeline.globalClockKey = "Root"; // ... called "Root".
                        chunkTimeline.rewindable = true; // ... and make it rewindable
                    }

                    // Add a TimeColor (custom class to color the object by its time scale, as seen in the video)
                    // You can find a similar class in the Chronos examples folder
                    TimeColor chunkTimeColor = chunk.GetComponent<TimeColor>();
                    if (chunkTimeColor == null)
                    {
                        // Ignore roads, tracks, bridges, etc.
                        if (!chunk.name.Contains("Track") && !chunk.name.Contains("Road") && !chunk.name.Contains("Bridge"))
                        {
                            chunkTimeColor = chunk.gameObject.AddComponent<TimeColor>();
                        }
                    }
                }

                // Explode the object (plugin method)
                // It's important to notice that we have to manually multiply by time.timeScale here
                // because the plugin's source doesn't use Chronos' PhysicsTimer methods, of course.
                fracturedObject.Explode(contact, force * time.timeScale);
            }
        }
    }
}