Search Unity

[Released] DestroyIt - Cinematic Destruction System

Discussion in 'Assets and Asset Store' started by DeadlyAccurate, Jun 14, 2014.

  1. julianr

    julianr

    Joined:
    Jun 5, 2014
    Posts:
    1,212
    Will do- thanks. Look forward to seeing the next pack!
     
  2. julianr

    julianr

    Joined:
    Jun 5, 2014
    Posts:
    1,212
    Hi! How would I increase the size of the exploded debris if I do not specify a destroyed prefab? Is it the Default Large Particle I'd need to increase?
     
  3. DeadlyAccurate

    DeadlyAccurate

    Joined:
    Apr 2, 2013
    Posts:
    186
    Depending on the size of the object that is being destroyed, it could be using either the Default Large Particle or the Default Small Particle. You just need to adjust the Start Size (and possibly the Emission Rate if you also want more debris).
     
    julianr likes this.
  4. julianr

    julianr

    Joined:
    Jun 5, 2014
    Posts:
    1,212
    Thanks. I decided to make some broken bricks and other elements, then placed them inside a group to be flung out with them, as the default particles throw out the shapes but the faces of the debris are smaller than the originals. Results look pretty good.
     
  5. DeadlyAccurate

    DeadlyAccurate

    Joined:
    Apr 2, 2013
    Posts:
    186
    Submitted to the asset store today, version 1.7, with some fixes, including the removal of a few Javascript standard assets.

    Changelog v1.7

    • Updated to Unity 2017.2
    • Fixed muzzle flash particle effect for M4 rifle - now uses custom simulation space to stay attached to rifle muzzle.
    • Removed unused JavaScript Standard Asset scripts.
    • Fixed missing references for rocket launcher on Mass Destruction Demo scene.
    • Fixed object pool warnings on SUV Showcase Demo scene when restarting the scene with the 'R' key.
     
    julianr likes this.
  6. paulojsam

    paulojsam

    Joined:
    Jul 2, 2012
    Posts:
    575
    how to make this compatible with ultimate survival i wonder
     
  7. zangad

    zangad

    Joined:
    Nov 17, 2012
    Posts:
    357
    Hi paulojsam,

    We've reached out to Winterbyte - the developers of the Ultimate Survival Unity asset and requested a voucher trade so we can test the integration.

    I suspect there won't be any issues, but is there something in particular you are concerned about regarding compatibility? For instance, are you planning to make a game that will use Ultimate Survival guns, and you want to know if you'll be able to damage/destroy DestroyIt props with them? That answer will help me focus my testing scope and get the answer you're looking for.
     
  8. paulojsam

    paulojsam

    Joined:
    Jul 2, 2012
    Posts:
    575
    Thank you zangad, yes, thats the case, to be able to destroy props with the ultimate survival guns.
     
  9. zangad

    zangad

    Joined:
    Nov 17, 2012
    Posts:
    357
    Just letting you know, we haven't forgotten about this question. We sent a followup email to Winterbyte since we haven't gotten a response yet.
     
  10. DeadlyAccurate

    DeadlyAccurate

    Joined:
    Apr 2, 2013
    Posts:
    186
    Submitted today.

    1.7.1
    (Jan 2018)
    • Cleaned up Standard Assets references so there are no assetId conflicts with DestroyIt when importing any Standard Assets package.
     
    julianr likes this.
  11. Michael2D

    Michael2D

    Joined:
    Mar 5, 2014
    Posts:
    17
    I would like to ask:
    Is it possible to make RFPS work with your asset?
    Because every bullet I use just raming to object but not taking damage...
    How to fix this??¨
    I dont know if you already answered this I looked whole forum but nothing about bullets for RFPS

    Thank you for any reply!
    Have a nice rest of a day!
    Michael
     
  12. zangad

    zangad

    Joined:
    Nov 17, 2012
    Posts:
    357
    Hi Michael,

    Thanks for reaching out to us. Yes, RFPS will work with DestroyIt. Here are step-by-step instructions for getting it to work in the simplest manner:

    1) Import DestroyIt
    2) Import Realistic FPS Prefab (RFPS)
    3) Open the FPS Sandbox scene
    4) Choose Window > DestroyIt > Setup (Minimal) from the Unity top menu
    5) Drag the DestroyIt script onto a crate in the scene
    6) Open the \Assets\RFPSP\Scripts\Weapons\WeaponBehavior.cs file in a text editor
    7) Inside the HitObject() method, paste this code at the specified point (see screenshot):
    Code (CSharp):
    1. DestroyIt.Destructible destObj = hit.collider.gameObject.GetComponent<DestroyIt.Destructible>();
    2. if (destObj != null)
    3. {
    4.     destObj.ApplyDamage(new DestroyIt.ImpactDamage()
    5.     {
    6.         DamageAmount = (int)damageAmt,
    7.         AdditionalForce = force,
    8.         AdditionalForcePosition = hit.point,
    9.         AdditionalForceRadius = 1f
    10.     });
    11. }


    8) Run the scene, pick up the shotgun, and shoot the crate



    As previously mentioned, this is the simplest use of DestroyIt - it just destroys the crate into a particle effect.

    From here, though, you can expand your destructible object to be as complex as you like, with damage effects, pre-fractured prefabs, child objects embedded inside, progressive damage textures, etc.
     
    ZGoodwin and Michael2D like this.
  13. DeadlyAccurate

    DeadlyAccurate

    Joined:
    Apr 2, 2013
    Posts:
    186
    Submitted today, version 1.8. This version primarily improves the demo assets, though it also includes an update to the nuke weapon particle effect. If you're not using any of the demo assets or the nuke, you don't need to update to this version.

    v1.8 (Apr 2018):
    • Updated the Nuke weapon particle effect
    • Replaced demo object #4 with a gas barrel model and replaced the explosion with one from the Unity Particle Pack
    • Replaced demo object #10 rock with a new rock
    • Retextured demo objects #12 and #13, cog box, and reduced number of textures used
    • Modified demo objects #17 and #18 targets to use only a single material
    • Adjusted the height and angle of the Nuke trigger GameObject on the First Person Controller
    • Reduced the size of several textures: track blinds, flag, pipe wrench, and rocket launcher sight
    • Modified the Flag prefab GameObject to remove the Hinge Joint due to Unity no longer allowing non-convex colliders to work with non-kinematic rigidbodies
     
    julianr, ZGoodwin and Arganth like this.
  14. recon0303

    recon0303

    Joined:
    Apr 20, 2014
    Posts:
    1,634
    Question, I noticed in your wastelands video, you can blow up the area in game. Now, is there a way to do this with Destroy it, but save the scene after wards as a prefab to use . as a static model after wards. Thanks!

    PS: wondering if this can work for any scene, I just used the wasteland as an example.
     
    ZGoodwin likes this.
  15. ZGoodwin

    ZGoodwin

    Joined:
    Jul 14, 2017
    Posts:
    31
    Unity Version: 2017.3.0f3
    DestroyIt: v1.8
    Invector Shooter: v1.2
    ERROR
    Assets/Invector-3rdPersonController/Basic Locomotion/Scripts/Generic/vDestructibleCollider.cs(24,25): error CS0246: The type or namespace name `vDamage' could not be found. Are you missing `Invector' using directive?

    Hello, this error is confusing.
     
  16. DeadlyAccurate

    DeadlyAccurate

    Joined:
    Apr 2, 2013
    Posts:
    186
    I'm not entirely clear about what you're asking, but DestroyIt doesn't fracture objects. The Wasteland packs are prefractured.

    But if you're wondering if you can save destroyed prefabs at runtime as new objects, yes you can, using the Object Exporter script from the Unity wiki to export a scene object as an .obj file.

    http://wiki.unity3d.com/index.php?title=ExportOBJ

    Note: You'll need to replace line 34
    Material[] mats = mf.renderer.sharedMaterials;​
    with
    Material[] mats = mf.GetComponent<Renderer>().sharedMaterials;
    Run the scene, destroy a model and then freeze the scene mid-destruction. We have scripts in the demo scene that will slow time (T) and freeze time (Y)
    While the scene is frozen, run the ObjExporter script from the File editor menu.

    Here's an example of us destroying a model in the scene...



    ...and here's the exported .obj model.



    This is just one object, but on the Destructible script, in the Destroyed Prefab section, you can assign all of your destroyed prefabs to be parented under a single GameObject that you then export as your scene .obj.
     
    Fibonaccov likes this.
  17. DeadlyAccurate

    DeadlyAccurate

    Joined:
    Apr 2, 2013
    Posts:
    186
    Are you using the scripts we posted here?
    https://forum.unity.com/threads/rel...destruction-system.251622/page-5#post-2863129

    We don't see vDamage anywhere in those scripts. Can you provide us your version of vDestructibleCollider?
     
  18. recon0303

    recon0303

    Joined:
    Apr 20, 2014
    Posts:
    1,634

    Yes I know that DestroyIt doesn't fracture objects. I fracture objects all the time in Modo, Maya. etc. but I also make my scenes in Modo , Maya where say for example you have a scene that is abandon and you normally place alot by hand..... Or use another process.


    I think using a tool like Destroy it...where you can in run time, blow up an area....Then be able to save it after wards as a prefab so you can used the blown up scene in a game....So modelers wont need to manually place all of this stuff.

    This way you can take the blown up scene, as a static prefab afterwards... no matter what it is.

    I hope I was more clear. Thanks.
     
    Last edited: Apr 28, 2018
  19. ZGoodwin

    ZGoodwin

    Joined:
    Jul 14, 2017
    Posts:
    31
    No, I am using the shooter instructions and files provided at https://forum.unity.com/threads/rel...destruction-system.251622/page-7#post-3156525

    I am using an updated code provided by red at http://invector.proboards.com/thread/237/destroyit-official-integration on Feb 17, 2018.

    NOTE: Both versions of vDestructibleCollider are returning the same error.

    vDamage is written on line 24
    Code (CSharp):
    1. using DestroyIt;
    2. using Invector.EventSystems;
    3. using UnityEngine;
    4.  
    5. // This script provides an easy way to setup ModelShark Studio's Destructible objects
    6. // to work with Invector's Third Person Controller Melee Combat Template.
    7.  
    8. // This script is automatically added to each collider when the vDestructible script is
    9. // on your Destructible object.
    10.  
    11. [RequireComponent(typeof(Collider))]
    12. public class vDestructibleCollider : MonoBehaviour, vIDamageReceiver
    13. {
    14.     public float ForceMultiplier { get; set; }
    15.     private Rigidbody rbody;
    16.     private Destructible destructible;
    17.  
    18.     void Awake()
    19.     {
    20.         destructible = GetComponentInParent<Destructible>();
    21.         rbody = GetComponentInParent<Rigidbody>();
    22.     }
    23.  
    24.     public void TakeDamage(vDamage damage, bool hitReaction = false)
    25.     {
    26.         if (ForceMultiplier <= 0f) // Default to 0.5f if for some reason ForceMultiplier hasn't been set.
    27.             ForceMultiplier = 0.5f;
    28.  
    29.         var point = damage.hitPosition;
    30.         var relativePoint = transform.position;
    31.         relativePoint.y = point.y;
    32.         var forceForward = relativePoint - point;
    33.  
    34.         if (rbody != null && destructible != null)
    35.         {
    36.             Debug.Log("[" + destructible.name + "] got hit for " + damage.damageValue + " points of damage!");
    37.             destructible.ApplyDamage(damage.damageValue);
    38.             rbody.AddForce(forceForward * (damage.damageValue * ForceMultiplier), ForceMode.Impulse);
    39.         }
    40.     }
    41. }
    42.  
     
    Last edited: Apr 28, 2018
  20. recon0303

    recon0303

    Joined:
    Apr 20, 2014
    Posts:
    1,634
    So sounds like this may work then, as I would want the scene saved after the destruction. Because typically I destroy my stuff in Modo or Maya.. Then save it... and use that. So looking for a way to do it in Unity. so by the sounds of it, this would work. Thanks
     
  21. DeadlyAccurate

    DeadlyAccurate

    Joined:
    Apr 2, 2013
    Posts:
    186
    Here's the updated vDestructibleCollider script.

    Code (CSharp):
    1.  
    2. using DestroyIt;
    3. using Invector.EventSystems;
    4. using Invector;
    5. using UnityEngine;
    6.  
    7. // This script provides an easy way to setup ModelShark Studio's Destructible objects
    8. // to work with Invector's Third Person Controller Melee Combat Template.
    9.  
    10. // This script is automatically added to each collider when the vDestructible script is
    11. // on your Destructible object.
    12.  
    13. [RequireComponent(typeof(Collider))]
    14. public class vDestructibleCollider : MonoBehaviour, vIDamageReceiver
    15. {
    16.     public float ForceMultiplier { get; set; }
    17.     private Rigidbody rbody;
    18.     private Destructible destructible;
    19.  
    20.     void Awake()
    21.     {
    22.         destructible = GetComponentInParent<Destructible>();
    23.         if (destructible == null)
    24.             destructible = GetComponent<Destructible>();
    25.         rbody = GetComponentInParent<Rigidbody>();
    26.     }
    27.  
    28.     public void TakeDamage(vDamage damage)
    29.     {
    30.         if (ForceMultiplier <= 0f) // Default to 0.5f if for some reason ForceMultiplier hasn't been set.
    31.             ForceMultiplier = 0.5f;
    32.  
    33.         var point = damage.hitPosition;
    34.         var relativePoint = transform.position;
    35.         relativePoint.y = point.y;
    36.         var forceForward = relativePoint - point;
    37.  
    38.         if (destructible != null)
    39.         {
    40.             Debug.Log("[" + destructible.name + "] got hit for " + damage.damageValue + " points of damage!");
    41.             destructible.ApplyDamage(damage.damageValue);
    42.             if (rbody != null)
    43.                 rbody.AddForce(forceForward * (damage.damageValue * ForceMultiplier), ForceMode.Impulse);
    44.         }
    45.     }
    46. }
    47.  
     
    julianr and ZGoodwin like this.
  22. ZGoodwin

    ZGoodwin

    Joined:
    Jul 14, 2017
    Posts:
    31
  23. zangad

    zangad

    Joined:
    Nov 17, 2012
    Posts:
    357
    Hi everyone,

    A customer sent us a good question and we thought we'd answer it here in case someone else had the same question.
    Yes, you can destroy a vehicle using a timed trigger, whether it's a cutscene with a timeline, or just a simple timed explosion. Destructible objects automatically react to explosions or other hazards (bullets, flying debris, etc) that are setup to damage them, so you just need to create a timed explosion and place it where you want it, and DestroyIt will handle the rest.

    We created a sample timed explosion script that works with our SUV demo scene. Just put the script on your explosive device, choose an explosion effect prefab, run the scene, and wait a few seconds. :)

    ExplodeAfter Script:
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. namespace DestroyIt
    4. {
    5.     /// <summary>This script will intantiate the specified explosion prefab after [seconds].</summary>
    6.     public class ExplodeAfter : MonoBehaviour
    7.     {
    8.         [Tooltip("Prefab to instantiate when time runs out.")]
    9.         public GameObject explosionPrefab;
    10.         [Tooltip("Seconds to wait before explosion.")]
    11.         public float seconds = 5f;
    12.  
    13.         private float timeLeft;
    14.         private bool isInitialized;
    15.  
    16.         void Start()
    17.         {
    18.             timeLeft = seconds;
    19.             isInitialized = true;
    20.         }
    21.  
    22.         void OnEnable()
    23.         {
    24.             timeLeft = seconds;
    25.         }
    26.  
    27.         void Update()
    28.         {
    29.             if (!isInitialized) return;
    30.  
    31.             timeLeft -= Time.deltaTime;
    32.             if (timeLeft <= 0)
    33.             {
    34.                 Instantiate(explosionPrefab, this.transform.position, Quaternion.identity);
    35.                 Destroy(this.gameObject);
    36.             }
    37.         }
    38.     }
    39. }
    Video of Results:

     
    Last edited: May 7, 2018
  24. serberusno1

    serberusno1

    Joined:
    Jan 28, 2017
    Posts:
    84
    Is there any functionality (or plans to add functionality) whereby you can destroy an object at a specified time after something collides with it? In other words, my character collides with an object and it doesn't get destroyed until a second or two later? This would be very handy for racing games. Also the ability to reset to the original object or another prefab after a certain time again would also be super useful.
     
  25. zangad

    zangad

    Joined:
    Nov 17, 2012
    Posts:
    357
    Hi serberusno1,

    I think I understand what you're asking for. Would it be similar to how in many FPS games, you shoot a red explosive barrel, and once it takes enough damage, it catches on fire and explodes after a few seconds?

    Back to your race car example, the car would get wrecked enough that it's considered totaled, then catch on fire and smoke, until several seconds later it finally explodes.

    If that's the effect you're looking for, the easiest way I can think of to do it is to add a script to your Destructible object that monitors its hit points. Once its hit points drop below a certain point-of-no-return value, it starts a timer that continuously does damage to the Destructible object until it is destroyed. To get the big finale explosion, set your destroyed prefab to a dismantled car with the explosion effect attached to it. That way it immediately explodes and flies apart when the destroyed prefab spawns in.

    Using a hit point monitor like this also gives you the option to have cars explode immediately if they take so much damage they bypass the timer and go straight to 0 hit points. For example, if the car slammed into a wall head-on at 150 mph, you might want an immediate destruction effect instead of a delayed one. Using a script like this would allow that to happen automatically.

    Here's what I put together that (I think) gives you the effect you're looking for. Put this on your object at the same level in the hierarchy as your Destructible script:

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. namespace DestroyIt
    4. {
    5.     public class AutoDamage : MonoBehaviour
    6.     {
    7.         public int startAtHitPoints = 30;
    8.         public float damageIntervalSeconds = 0.5f;
    9.         public int damagePerInterval = 5;
    10.  
    11.         private bool isInitialized;
    12.         private Destructible destructible;
    13.         private bool autoDamageStarted;
    14.  
    15.         void Start()
    16.         {
    17.             destructible = gameObject.GetComponent<Destructible>();
    18.             if (destructible == null)
    19.             {
    20.                 Debug.LogWarning("No Destructible object found! AutoDamage removed.");
    21.                 Destroy(this);
    22.             }
    23.             isInitialized = true;
    24.         }
    25.  
    26.         void Update()
    27.         {
    28.             if (!isInitialized) return;
    29.             if (destructible == null) return;
    30.             if (autoDamageStarted) return;
    31.  
    32.             if (destructible.currentHitPoints <= startAtHitPoints)
    33.             {
    34.                 InvokeRepeating("ApplyDamage", 0f, damageIntervalSeconds);
    35.                 autoDamageStarted = true;
    36.             }
    37.         }
    38.  
    39.         void ApplyDamage()
    40.         {
    41.             if (destructible == null) return;
    42.  
    43.             destructible.ApplyDamage(damagePerInterval);
    44.         }
    45.     }
    46. }
    If this fits your needs, we may add this feature to the Destructible script - I can see it being something others might like. There are still other things we need to consider when adding it to DestroyIt, though, such as how the timer would need to be stopped if the object is repaired above the threshold, etc.

    The ability to reset a destroyed object back to its original prefab is already on our backlog. I've bumped up the priority since you are the second customer to ask for this feature.

    The way I see this feature working is, we would add a ResetPrefab field to the Destructible script. There, you would assign the prefab you want to reset it to whenever Reset() is called on the object. The DestroyIt code would need to be re-worked so the Destructible object and script always remain in the game (currently, they are removed from the game and replaced with the destroyed prefab, which has no knowledge of the original it came from).

    Destroyed prefabs would spawn in parented under the Destructible object when destroyed. If Reset() is called on a Destructible object with no assigned ResetPrefab, then the original gameObject would be reset and re-activated. Particle effects would also need to be reset. In addition, the ResetPrefabs would need to be auto-pooled like the destroyed prefabs currently are, for performance.

    As you can see, there are a lot of considerations to make this fit cleanly in DestroyIt. But we think it's a great feature, and we'll add it to the asset as soon as we can work through the details. Thanks for the suggestion!
     
    Last edited: May 20, 2018
    Fibonaccov and julianr like this.
  26. serberusno1

    serberusno1

    Joined:
    Jan 28, 2017
    Posts:
    84
    Hey thank you so much for that! I'll try it out ASAP and get back to you on how it works. Sounds like exactly what I need plus a little more :)
     
  27. DeadlyAccurate

    DeadlyAccurate

    Joined:
    Apr 2, 2013
    Posts:
    186
    Submitted v1.9 today

    Changelog

    • Updated DestroyIt to Unity 2018.1
    • Replaced wooden chest (Main Scenarios Scene, #14) with a model that uses a single material
    • Fixed explosion effect on explosive barrel (Main Scenarios Scene, #4)
    • Cleaned up meshes in demo scenes (removed n-gons) to correct texture import warnings
    • Removed legacy shader for palm tree (Main Scenarios Scene, #21)
    • Fixed rotating particles on ConcreteDebris particle effect
    • Removed FadeTreeSwaying script since it only worked with legacy nature shader
     
    led_bet and julianr like this.
  28. serberusno1

    serberusno1

    Joined:
    Jan 28, 2017
    Posts:
    84
    Hey, tried your timed destructible script but getting this error when I attach it to my object
     

    Attached Files:

  29. zangad

    zangad

    Joined:
    Nov 17, 2012
    Posts:
    357
  30. DeadlyAccurate

    DeadlyAccurate

    Joined:
    Apr 2, 2013
    Posts:
    186
    We've just released a FREE destructible pack pre-configured to work with DestroyIt!

    Destructible Decoratives




    All the models share a single 4K texture set.

    Download it today and check it out. And if you don't need destruction, you can still use the undestroyed models in your game!
     
    led_bet and julianr like this.
  31. julianr

    julianr

    Joined:
    Jun 5, 2014
    Posts:
    1,212
    Thanks - it will add to what I already have. Nice work! I'm still set for making add-on art packs for DestroyIt! Once I've finished the current project.
     
    DeadlyAccurate likes this.
  32. reggie_sgs

    reggie_sgs

    Joined:
    Jun 29, 2014
    Posts:
    276
    I purchased DestroyIt a while back and we're just now getting around to trying it out for our upcoming PS4 game Honor &Duty: D-Day. We're doing a PSVR battlefield style game and want to have a lot of destructible items.

    One immediate problem is the use of ints for damage amounts instead of floats. Is there any way you can switch over to using floats? This causes real problems since our damage system and many others like UFPS use floats for damage amounts. This is causing syncing issues between DestroyIt and our system due to the rounding of float damage to ints.

    With damage, you have many factors that can affect the amount of damage dealt and you typically have a number of multipliers that vary the amount of damage. You might take a base amount of 5 for a bullet, multiply it by 1.5 for the weapon, decrease it by 0.25 because they're hip firing, decrease it by 0.5 because it went through some wood, etc.. so you really need floats to store damage amounts.

    Thanks,
    Reggie
     
  33. zangad

    zangad

    Joined:
    Nov 17, 2012
    Posts:
    357
    Hi Reggie,

    Thanks for the suggestion. I took a look at it, and was able to convert DestroyIt to use floats for damage in about 30-40 minutes and there were no obvious breaking changes. There were a few warnings about "loss of precision", and in a few places we're doing comparisons to zero, so I'll need to convert those to Mathf.Approximately() comparisons. Other than that, we would just need to do a lot of regression testing before releasing it. But it seems like a pretty straight-forward and minimal impact change for customers.

    The only breaking changes would be to customers who have (A) already written a lot of custom DestroyIt code for their game - in which case we will warn them that they should not update their DestroyIt version, and (B) anyone who is taking advantage of the DestroyItReady stubs to create and sell their own DestroyIt-Ready models.

    But I don't think either of these is a deal-breaker, and it does make DestroyIt more compatible with other FPS packages. We will put your suggestion on our backlog and try to get it in with the next release, pending any issues. Thanks!
     
    Last edited: Jun 30, 2018
  34. reggie_sgs

    reggie_sgs

    Joined:
    Jun 29, 2014
    Posts:
    276
    That's great, thanks! I already did the conversion on my end and haven't seen any issues. I really don't like doing this since every time an asset is updated, you have to merge your changes in and it can be a real pain. I'm glad it will be in with your next update. The only thing I couldn't get working was the custom script inspector for the current and max hit points. For some reason it keeps setting them to zero so I disabled that and just have to switch to debug mode on the inspector to set these. Yea it should be backwards compatible since you can pass an int where a float is expected but not the other way. I also sent you an e-mail with a few other things so let me know if you don't receive it. Thanks again.
     
  35. DeadlyAccurate

    DeadlyAccurate

    Joined:
    Apr 2, 2013
    Posts:
    186
    Did you send it to modelsharkstudio@gmail.com or through our website? It didn't arrive. Can you send it again?
     
  36. reggie_sgs

    reggie_sgs

    Joined:
    Jun 29, 2014
    Posts:
    276
    It was sent to support@modelshark.com which I got from the docs. I just forwarded it to your gmail address so let me know if you don't get it. Thanks!
     
  37. DeadlyAccurate

    DeadlyAccurate

    Joined:
    Apr 2, 2013
    Posts:
    186
    OK, that one arrived. I'll look into that other email address and see if emails are getting hung up.
     
  38. BrianF127

    BrianF127

    Joined:
    May 1, 2018
    Posts:
    4
    I have been using UFPS for a few years now and just purchased DestroyIt. Do you plan to revise your UFPS and DestroyIt integrated instructions? The previous instructions now produce errors. Thanks in advance
     
  39. DeadlyAccurate

    DeadlyAccurate

    Joined:
    Apr 2, 2013
    Posts:
    186
    Does it throw errors with this update to the code?
    https://forum.unity.com/threads/rel...destruction-system.251622/page-6#post-2961535

    Also, can you describe the errors you're getting?
     
  40. BrianF127

    BrianF127

    Joined:
    May 1, 2018
    Posts:
    4
    Thanks for the quick response. The error I am getting is as follows. Not sure how to clear this up.

    Assets/UFPS/Base/Scripts/Gameplay/Combat/vp_Explosion.cs(225,26): error CS0128: A local variable named `dest' is already defined in this scope

    Code (CSharp):
    1. // apply shockwave to all rigidbodies and players within range, but
    2.         // ignore small and walk-thru objects such as debris, triggers and water
    3.         Collider[] colliders = Physics.OverlapSphere(Transform.position, Radius, vp_Layer.Mask.IgnoreWalkThru);
    4.         foreach (Collider hit in colliders)
    5.  
    6.         {
    7.  
    8.             // If the object is a ModelShark Destructible, apply damage to it.
    9.             Destructible dest = hit.GetComponentInParent<Destructible>();
    10.         if (dest != null)
    11.             dest.ApplyDamage(new ExplosiveDamage() { BlastForce = Force, Position = OriginalSource.position, Radius = Radius, UpwardModifier = UpForce });
    12.  
    13.  
    14.             // If the object is a ModelShark Destructible, apply damage to it.
    15.             Destructible dest = hit.GetComponentInParent<Destructible>();
    16.             if (dest != null)
    17.                 dest.ApplyExplosiveDamage(new ExplosionInfo() { BlastForce = Force, Position = OriginalSource.position, Radius = Radius, UpwardModifier = UpForce });
    18.  
    19.  
    20.             if (hit.gameObject.isStatic)
    21.                 continue;
    22.  
    23.             m_DistanceModifier = 0.0f;
    24.  
    25.             if ((hit != null) && (hit.transform.root != transform.root))
     
  41. DeadlyAccurate

    DeadlyAccurate

    Joined:
    Apr 2, 2013
    Posts:
    186
    It's been a long time since I've done much C# coding (zangad does all the asset's code), but it looks like you're declaring dest as type Destructible in both lines 9 and 15.

    Shouldn't line 15 just be:
    dest = hit.GetComponentInParent<Destructible>();
     
  42. BrianF127

    BrianF127

    Joined:
    May 1, 2018
    Posts:
    4
    I am very much a novice. Changing to dest = hit.GetComponentInParent<Destructible>(); only creates more errors. Maybe zangad can provide a solution in the future.
     
  43. zangad

    zangad

    Joined:
    Nov 17, 2012
    Posts:
    357
    DeadlyAccurate is correct, the most noticeable immediate issue with the code in your post is the variable "dest" is declared twice within the same scope. The error message also indicates this: "A local variable named `dest' is already defined in this scope".

    To fix, delete lines 14-17 (inclusive) because they are an exact copy of lines 8-11.

    If you still get more errors after deleting the duplicated lines, please email us at modelsharkstudio@gmail.com with the error messages you're getting and the relevant code.
     
  44. BrianF127

    BrianF127

    Joined:
    May 1, 2018
    Posts:
    4
    That did the trick. Thought I tried deleting the lines on Friday, but then again it was Friday.
    Thanks again
     
  45. sdcrume

    sdcrume

    Joined:
    Oct 2, 2016
    Posts:
    3
    Hey all,

    I recently updated to the most recent version of Invector TPC so that I could use their new AI system. When I completed the update from the asset store I started to get an error in my vDestructibleCollider.cs script. If I utilize the suggested fix I can destroy objects by running into them but not by shooting them. I have included an image showing the error and here is my code:

    Code (CSharp):
    1. using DestroyIt;
    2. using Invector;
    3. using Invector.EventSystems;
    4. using UnityEngine;
    5.  
    6. // This script provides an easy way to setup ModelShark Studio's Destructible objects
    7. // to work with Invector's Third Person Controller Melee Combat Template.
    8.  
    9. // This script is automatically added to each collider when the vDestructible script is
    10. // on your Destructible object.
    11.  
    12. [RequireComponent(typeof(Collider))]
    13. public class vDestructibleCollider : MonoBehaviour, vIDamageReceiver
    14. {
    15.     public float ForceMultiplier { get; set; }
    16.     private Rigidbody rbody;
    17.     private Destructible destructible;
    18.  
    19.     void Awake()
    20.     {
    21.         destructible = GetComponentInParent<Destructible>();
    22.         rbody = GetComponentInParent<Rigidbody>();
    23.     }
    24.  
    25.     public void TakeDamage(vDamage damage, bool hitReaction = false)
    26.     {
    27.         if (ForceMultiplier <= 0f) // Default to 0.5f if for some reason ForceMultiplier hasn't been set.
    28.             ForceMultiplier = 0.5f;
    29.  
    30.         var point = damage.hitPosition;
    31.         var relativePoint = transform.position;
    32.         relativePoint.y = point.y;
    33.         var forceForward = relativePoint - point;
    34.  
    35.         if (rbody != null && destructible != null)
    36.         {
    37.             Debug.Log("[" + destructible.name + "] got hit for " + damage.damageValue + " points of damage!");
    38.             destructible.ApplyDamage(damage.damageValue);
    39.             rbody.AddForce(forceForward * (damage.damageValue * ForceMultiplier), ForceMode.Impulse);
    40.         }
    41.     }
    42. }
    43.  
    As you can see in the image below the error is on the vIDamageReciever and it says that 'vIDamageReciever' is an ambiguous reference between 'Invector.EventSystems.vIDamageReciever' and 'Invector.vIDamageReciever'.

    I am at a bit of a loss on how to fix this issue and do not understand my Invector seems to change so many references with each update. It makes it a real pain to update without a mountain of issues to fix.

    Thank you for any help in advance.


    DestroyItError.jpg
     
    Last edited: Jul 31, 2018
  46. zangad

    zangad

    Joined:
    Nov 17, 2012
    Posts:
    357
    Hi sdcrume,

    Yes, it looks like there were some changes in the latest version of the Invector TPC AI Template Beta that broke backwards compatibility with the integration scripts we had previously written. Please replace your vDestructibleCollider and vDestructible scripts with the ones provided below.

    Assumptions:
    • You are using Unity 2018.2 or later
    • You are using the latest version of DestroyIt (1.9)
    • You are using the AITemplate_Betav0.1.unitypackage from Invector
    • You are following the instructions in this post regarding integrating with Invector TPC
    If any of these assumptions are incorrect, you may need to zip and upload your project so we can take a look at it. There are many variables with integration, and also many versions of the Invector packages.

    vDestructibleCollider.cs
    Code (CSharp):
    1. using DestroyIt;
    2. using Invector;
    3. using UnityEngine;
    4. // This script provides an easy way to setup ModelShark Studio's Destructible objects
    5. // to work with Invector's Third Person Controller Melee Combat Template.
    6. // This script is automatically added to each collider when the vDestructible script is
    7. // on your Destructible object.
    8. [RequireComponent(typeof(Collider))]
    9. public class vDestructibleCollider : MonoBehaviour, vIDamageReceiver
    10. {
    11.     public float ForceMultiplier { get; set; }
    12.     private Rigidbody rbody;
    13.     private Destructible destructible;
    14.     void Awake()
    15.     {
    16.         destructible = GetComponentInParent<Destructible>();
    17.         if (destructible == null)
    18.             destructible = GetComponent<Destructible>();
    19.         rbody = GetComponentInParent<Rigidbody>();
    20.     }
    21.  
    22.     public OnReceiveDamage onReceiveDamage { get; private set; }
    23.  
    24.     public void TakeDamage(vDamage damage)
    25.     {
    26.         if (ForceMultiplier <= 0f) // Default to 0.5f if for some reason ForceMultiplier hasn't been set.
    27.             ForceMultiplier = 0.5f;
    28.         var point = damage.hitPosition;
    29.         var relativePoint = transform.position;
    30.         relativePoint.y = point.y;
    31.         var forceForward = relativePoint - point;
    32.         if (destructible != null)
    33.         {
    34.             Debug.Log("[" + destructible.name + "] got hit for " + damage.damageValue + " points of damage!");
    35.             destructible.ApplyDamage(damage.damageValue);
    36.             if (rbody != null)
    37.                 rbody.AddForce(forceForward * (damage.damageValue * ForceMultiplier), ForceMode.Impulse);
    38.         }
    39.     }
    40. }
    vDestructible.cs
    Code (CSharp):
    1. using DestroyIt;
    2. using Invector;
    3. using UnityEngine;
    4.  
    5. // This script provides an easy way to setup ModelShark Studio's Destructible objects
    6. // to work with Invector's Third Person Controller Melee Combat Template.
    7.  
    8. // Place this script on your Destructible object, at the same level as the Destructible
    9. // script.
    10.  
    11. [RequireComponent(typeof(Destructible))]
    12. public class vDestructible : MonoBehaviour
    13. {
    14.     public float forceMultiplier = 0.5f;
    15.     public GameObject defaultHitEffect;
    16.  
    17.     void Awake()
    18.     {
    19.         Destructible destructible = GetComponent<Destructible>();
    20.         Collider[] colliders = destructible.GetComponentsInChildren<Collider>();
    21.         for (int i=0; i<colliders.Length; i++)
    22.         {
    23.             if (!colliders[i].isTrigger) // Ignore trigger colliders
    24.             {
    25.                 // Add the DestructibleCollider script to each collider and configure it.
    26.                 vDestructibleCollider dc = colliders[i].gameObject.GetComponent<vDestructibleCollider>();
    27.                 if (dc == null)
    28.                     dc = colliders[i].gameObject.AddComponent<vDestructibleCollider>();
    29.  
    30.                 dc.ForceMultiplier = forceMultiplier;
    31.  
    32.                 // If a Default Hit Effect was specified, add the HitDamageParticle script to each collider.
    33.                 if (defaultHitEffect != null)
    34.                 {
    35.                     vHitDamageParticle hdp = colliders[i].gameObject.GetComponent<vHitDamageParticle>();
    36.                     if (hdp == null)
    37.                         hdp = colliders[i].gameObject.AddComponent<vHitDamageParticle>();
    38.  
    39.                     hdp.defaultDamageEffect = defaultHitEffect;
    40.                 }
    41.             }
    42.         }
    43.     }
    44. }
    When I followed the instructions in the post on integrating Invector with DestroyIt and updated my scripts with the ones above, I got no errors and was able to give myself a handgun in the AI_Action scene, and shoot the destructible column until it was destroyed.



    Hope this helps! Please let us know if it doesn't work for you.
     
    julianr likes this.
  47. sdcrume

    sdcrume

    Joined:
    Oct 2, 2016
    Posts:
    3
    Worked perfectly! Thank you so much!
     
  48. RunSwimFly

    RunSwimFly

    Joined:
    Mar 2, 2011
    Posts:
    34
    First I'd like to congratulate you on an excellent product. Saved me so much time and far better than the system I had designed myself before I was fortunate enough to come across Destroyit.

    I've come across two apparent inconsistencies in the way that damage is calculated. I've got work arounds for both of them but just wanted to check my approach.

    If I create a game object of say 1000 kg and place a Destructible script on it and impact it with a low mass high velocity projectile then the damage it receives is roughly 10 times the damage it receives if I make the target 100 kg. The damage appears to be determined by the average of the mass of the Destructible object and the impactor. This also has the result that the mass of the impactor is largely irrelevant (if it is small compared to the object it is hitting).

    The work around for this is to place the Destructible script on a child object and use a Destructible parent script on the parent rigid body. In this case the damage applied is the same as if the target had no rigidbody at all. I'm sure there would be a code workaround if I wanted to dig down into it but I'd rather not change the package too much.

    The second problem is that the RigidBodyProjectile script generates additional unneeded ProcessDestructibleCollision calls when it is applied to a projectile that is hitting a Destructible object which is a child of a Rigidbody-Destructible Parent object as described above. Moreover these additional calls factor in the mass of the target as above and thus dwarf any effect that the mass of the small impactor might have.

    In order to fix this I changed line 48 of RigidBodyProjectile from
    if (other.attachedRigidbody == null || other.attachedRigidbody.GetComponent<Destructible>() == null)
    to
    if (other.attachedRigidbody == null)

    This way it still applies a suitable amount of damage to objects with no rigidbody without applying extra massive damage to objects which have a rigidbody.
     
    Flurgle likes this.
  49. zangad

    zangad

    Joined:
    Nov 17, 2012
    Posts:
    357
    Hi RunSwimFly,

    Thank you for the kind words. It means a lot.

    Yes, you're correct that the damage is calculated using the average mass of the two objects. This is a simplification that works well for most scenarios, but not for rigidbody bullets.

    A bit of history...when we first started writing DestroyIt (Unity 4.0), we had the intention of including rigidbody bullets. But the physics in Unity weren't ready for that back then. There was the "bullet through paper" collider issue, where fast moving objects would pass through slow/stationary objects. Then there was the issue of how to calculate actual force, not just velocity magnitude.

    The community came up with clever solutions to these problems, but in the end, rigidbody bullets just felt too "hacky" with all the code workarounds and raycasting, so we dropped them from DestroyIt and used HitScan bullets for the rifle. We still liked the idea of a projectile, so we made the rigidbody collider larger and slower, and that became the Cannonball in our demo scene.

    So fast forward to today, the "bullet through paper" issue was fixed a while back (with Physx 3.3 I believe). And I just revisited the old forum post on calculating projectile force, and the good news is it sounds like there is a now a Collision.Impulse property which - if it works as expected - is what we should be using in DestroyIt to calculate impact force and damage. And with that, we could probably put rigidbody bullets back into the DestroyIt demo scenes, which would give everyone examples of how to do it for their games.

    I've put this on our to-do list for DestroyIt, but using Collision.Impulse is a fundamental change in how it calculates collision damage, and would need to be tested a lot. Plus we have several other things in flight so it might take a while for us to get the changes in. However, your fix of ignoring the rigidbody mass for one of the objects is a good workaround. Depending on your game, you may not care what the mass of the projectile is against a much larger, much more massive object. And you definitely don't want them averaged, so I think that's a good workaround.

    Looking at the code on this, I think you're right - it does seem as though it would process a collision on an object that would have already processed a collision in its own OnCollisionEnter() method.

    I'm not sure why that extra OR condition is on there - possibly to fix a different issue - but I'll take a closer look at that file's revision history in source control to see if there's a reason for it. In the meantime, I've added this one to our Bug list, thank you for mentioning it!
     
    Flurgle likes this.
  50. p_hergott

    p_hergott

    Joined:
    May 7, 2018
    Posts:
    414
    Using third person cover controller. To damage objects, is there just a script to put on bullets that enables damage to objects? Im not a coder. Haha.