Search Unity

[Released] DestroyIt - Cinematic Destruction System

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

  1. RunSwimFly

    RunSwimFly

    Joined:
    Mar 2, 2011
    Posts:
    34
    Thanks for the reply. I'd used Collision.Impulse in my prototype code before integrating DestroyIt. I just tried it then by replacing the impactDamage calculation in ProcessDestructibleCollision with:

    impactDamage = 0.0171f * collision.impulse.magnitude/Time.fixedDeltaTime;

    This almost precisely mirrors the results for the existing code for both direct and oblique impacts on objects without rigidbodies and with Destructible objects nested below rigid bodies while fixing the issue where both a rigidbody and a Destructible script are on the same object.

    I understand though that you need to be a little more cautious than me :)
     
  2. zangad

    zangad

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

    It depends on your game and which third party package you're using. Is this the asset you're using: Third Person Cover Shooter? Let us know specifically which package you're using and we'll request a copy from the developer so we can see what would be involved in integrating it with DestroyIt.

    We've done several integration tutorials in the past. The general process is always the same, the difference is in how they are implemented.

    The basic principle is, you find the code in your character controller asset package that handles bullet impacts. Sometimes, it will have its own damage system that you can add DestroyIt checks to, and other times it just handles particle effects or bullet hole decals. Regardless, this is where you add the code to check the impacted object for our Destructible script, and if it exists, apply damage.

    Here's the code, it's only a few lines. But where to put this code depends on the specific asset package you're using.
    Code (CSharp):
    1. DestroyIt.Destructible destObj = objectHit.collider.gameObject.GetComponent<DestroyIt.Destructible>();
    2. if (destObj != null)
    3.     destObj.ApplyDamage(10); // apply 10 points of damage to object hit.
    I hope that helps, please let us know if you need more assistance in integrating DestroyIt.
     
  3. zangad

    zangad

    Joined:
    Nov 17, 2012
    Posts:
    357
    Perfect! Thank you for the feedback. We will still regression-test the change of course, but it sounds like you're not having any issues with the Collision.Impulse change.

    Just out of curiosity, why is 0.0171f being multiplied by the impulse over time? Is that the multiplier you needed to get similar damage numbers to what DestroyIt was giving before the change?

    Thanks again for the feedback and help!
     
  4. RunSwimFly

    RunSwimFly

    Joined:
    Mar 2, 2011
    Posts:
    34
    Yes, I'd set up a test environment with a variety of objects of different masses and angles to my firing position. In all cases that multiplier replicated the existing damage amount to within a fraction of a percent. So, with the exceptions noted above, your existing code appears to be returning a result which is already proportional to Collision.Impulse.

    I've come up against some other problems with using high speed projectiles:
    https://forum.unity.com/threads/col...-high-velocity-has-unexpected-results.553501/
    I think the collision solver is making direct positional displacements to stop colliders penetrating and by using high speed low mass projectiles I'm pushing it into uncharted territory. So I may end up doing some ray (segment) casting or using triggers after all.
     
    zangad likes this.
  5. RunSwimFly

    RunSwimFly

    Joined:
    Mar 2, 2011
    Posts:
    34
    I noticed that sometimes damaging my vehicles when they were travelling at speed would result in them almost stopping instantaneously. This lead to the discovery that destroyed prefabs never acquire the velocity of the Destructible object that spawned them. (Although they sometimes appear that they do since they are quickly accelerated from a standing start by collisions with the main vehicle) I've tracked this down to 2 causes.

    One is that Rigidbody in Destructible, and hence VelocityFixedUpdate, will only be set if the rigidbody is on the same object as the Destructible component. Thus I changed line 112 in Destructible.cs from:

    Rigidbody = GetComponent<Rigidbody>();
    to
    Rigidbody = GetComponentInParent<Rigidbody>();

    The other problem is that while debris copy the velocity of the old object the destroyed prefabs do not. So in ProcessDestruction in DestructionManager.cs just after the line that reads:

    GameObject newObj = ObjectPool.Instance.Spawn(destroyedPrefab, oldObj.PositionFixedUpdate, oldObj.RotationFixedUpdate, oldObj.GetInstanceID());
    I inserted the lines:
    Rigidbody [] rigidbodies = newObj.GetComponentsInChildren<Rigidbody>();
    for (int i = 0; i < rigidbodies.Length; i++)
    rigidbodies.velocity = oldObj.VelocityFixedUpdate;

    The destroyed prefabs now carry on with the old velocity as expected.

    Another change I've made is to make damage proportional to the square of relative velocity (ie proportional to kinetic energy rather than momentum.). This is probably a matter of taste but it works well for me as I found that without this I either had high velocity weapon fire barely scratching the vehicles or minor inter vehicle collisions causing instant wrecks.
     
    zangad likes this.
  6. zangad

    zangad

    Joined:
    Nov 17, 2012
    Posts:
    357
    Thanks for sharing your the results of your fixes. Good catch on the destroyed prefabs not inheriting old objects' velocity. I've put that on our to-do list to fix, and we'll add a new scenario in the main demo scene of DestroyIt to regression test it going forward.

    I think we didn't notice that because the way our destructible objects are setup - when they are destroyed, the parent object is just a container for the debris. But you're right, the parent prefab object should inherit velocity from the destroyed object.

    We'll also take a closer look at the damage calculations. I like the idea of adding more weight to kinetic energy rather than straight mass/velocity multipliers. I agree it's probably a personal preference, but I also think most customers would expect damage calculations to work this way. Thanks again for sharing how you applied your fixes. That helps a lot.
     
  7. RunSwimFly

    RunSwimFly

    Joined:
    Mar 2, 2011
    Posts:
    34
    I’ve been looking at pooling lately. I’m instantiating new destructible objects as my game progresses and thus none of them are around to be pooled (even though they are set to auto pool) when ObjectPool starts.

    Thus when InstantiateDebris is called there’s no PooledRigidbodies and DebrisRigidBodies gets set to null. And then none of the code under

    if (DebrisRigidbodies!=null)

    gets called which results in nothing being assigned to the debris layer and none of the parent velocities being copied to the debris. Hence my problem with velocity from the previous post which I fixed down the bottom of ProcessDestruction.

    I’ve now replaced that fix by removing the if (debrisRigidBodies != null) condition from InstantiateDebris and adding it to the start of the if (debrisRigidBodies.Length == 0) condition. The following code now actually gets called on my dynamic destructible objects and they are tagged as debris and have their velocities correctly set.

    Having done all this I’ve now realised that maxPersistentDebris simply deactivates debris but leaves the deactivated game objects in the scene. In my case this results in a rapid accumulation of deactivated objects and no effective pooling. It appears that the only built in mechanism to re-pool an object is to attach a Pool After script to it. Is that correct? It seems to be working for the BulletHit etc objects but I haven’t tried it as yet with my compound objects.
     
    zangad likes this.
  8. RunSwimFly

    RunSwimFly

    Joined:
    Mar 2, 2011
    Posts:
    34
    I just tried replacing
    debris.Disable()
    with
    ObjectPool.Instance.PoolObject(debris.GameObject, true);
    when ActiveDebrisCount > maxPersistentDebris

    Seems to work as expected (provided the prefab name been added to the object pool) and negates the need to add PoolAfter on my debris. Also PoolAfter wouldn't have coexisted well with excess debris being disabled as this would have disabled the PoolAfter update function and stopped them ever timing out and being added to the pool.
     
    zangad likes this.
  9. zangad

    zangad

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

    We have Scenario #25 in our demo scene that instantiates a dynamic destructible object at runtime, and using that as test, I'm unable to reproduce the issue described. When I step through the code, it does populate the collection of debris rigidbodies and steps into the if (debrisRigidbodies != null) code.

    One thing that Scenario #25 is possibly doing differently is that it uses the DynamicDestructible.cs script to spawn in the destructible object. That was our solution to the pooling issue for dynamic objects created at runtime. I'm not sure if that would work for your game, just throwing it out there as the option we use to register dynamic destructible objects with the object pooler.
    Yes, you're correct, the debris gets disabled after it reaches the maxPersistentDebris threshold, but the objects don't get destroyed/re-pooled. The PoolAfter.cs script was provided as an option for resetting and re-pooling destroyed objects, but there is currently no system in place to automatically find and collect those disabled objects. We have a task on our backlog to do just that:
    I've bumped up the priority of this task, based on your feedback. At the time, I didn't like the idea of adding a bunch of "polling" scripts to the Update loop (one for each active destroyed object), but it sounds like the benefits might outweigh the added processing. It would definitely fix the accumulation of deactivated debris you described. Let me know what you think, we can tweak the proposed solution if there's a better option.
    If that solution works for your game, I would go with it. It's definitely more performant to use the existing threshold polling to re-pool a destroyed object than the method I mentioned above that introduces a polling script for each one. The only thing I can see is that method will sometimes re-pool an entire object that only has some of its debris disabled.

    For example, if you have a destroyed object with 10 pieces of debris in the scene, and 5 of the pieces get disabled because the maxPersistentDebris threshold is reached, then the entire object would be re-pooled and the remaining visible debris would disappear. We wanted to avoid this, as it might be jarring to the player. However, it might not matter for your game, especially if your debris threshold is high enough and the game is structured in a way that a player would never notice the older visible debris objects disappearing. If that's the case, then your method is preferable for performance. It really depends on how important it is in your game that debris never disappears while a player is looking at it.

    Hope that makes sense, please let me know if it doesn't. And thanks for your feedback, very good discussions! :)
     
  10. RunSwimFly

    RunSwimFly

    Joined:
    Mar 2, 2011
    Posts:
    34
    I don’t think the DynamicDestructible script is going to help me here. The dynamic objects I’m creating are entire vehicles, each with their own hierarchy of Destructible components.

    Thanks for the warning on my re-pooling solution. I’ll keep an eye out and adjust my solution if I see too much noticeable debris removal.

    Task #92 sounds like it would work well. I assume one would still need to manually add the destroyed prefabs and counts to Object pool in the inspector? Otherwise the debris would be destroyed rather than pooled.

    For my own purposes I’ve added a function to ObjectPool which will take a GameObject and then add all the destroyedPrefabs it finds in any Destructible children to the prefabsToPool list along with a suitable count. Then at the start of each level I run through my vehicle creation roster and call that function on each unique vehicle that I find.

    I’m enclosing all my additions in defines so I can compare them against the next iteration of the library and remove them if they are no longer needed. Enjoying the discussion as well :)
     
  11. RunSwimFly

    RunSwimFly

    Joined:
    Mar 2, 2011
    Posts:
    34
    I've been using the DestroyIt SUV model for testing and noticed that the debris seemed to be taking up more of the Physics FixedUpdate than I would have expected. When I profiled it I noticed that about half of the debris never went to sleep.

    As a test I tried dropping 100 copies of the SUV_Door_Back_DEST into my environment spaced such that they are only in contact with the terrain and not with each other. None of them went to sleep and they took up 15% of frame time.

    I tried disabling the two side colliders that border the window and all of the doors went to sleep and took up 3.9% of frame time. I then tried reenabling the side colliders but rescaling their Y dimension from 0.7 to 0.4 such that there was no overlap between any of the colliders and all but a few of the doors went to sleep and took 8% of frame time.

    It didn't make sense to me that colliders attached to the same rigidbody should be interfering with each other even if they overlapped but then I noticed that the z components of the child collider positions were all non zero and slightly different to each other. When I zeroed them and returned them to their original overlapping scale all the doors went to sleep and performance was the same as disabling the side colliders. So it appears that somehow the slight offset combined with the overlap was creating a geometry which never rested on the ground properly.

    I guess the moral, if there is one, is to test any compound collider objects and make sure they go to sleep. Not particularly important for your demo scene but certainly useful for me before I get any modelling done.
     
    Last edited: Sep 23, 2018
    zangad likes this.
  12. zangad

    zangad

    Joined:
    Nov 17, 2012
    Posts:
    357
    Wow, that's weird. Yeah, I was under the same assumption, that compound colliders would not interfere with each other in regards to rigidbody sleep thresholds. I never profiled that assumption, though. Very good find.

    I've added a to-do task for us to look at the compound colliders again and test the rigidbody sleep thresholds for the objects in our demo scenes. This should especially help with objects like the SUV and marble columns, which use compound colliders. We originally used mesh colliders for those complex objects, but noticed a big performance boost when switching to compound colliders. It sounds like if we zero out the transforms and scales on those colliders, we could possibly get another performance boost, especially when using mass/heavy destruction with lots of debris in the scene.

    Thank you for the detailed feedback! It's very appreciated.
     
  13. RunSwimFly

    RunSwimFly

    Joined:
    Mar 2, 2011
    Posts:
    34
    It is strange. I don't think there's any interaction between the colliders in a compound collider object. It's just that they can form a somewhat irregular shape that just just keeps jittering as it lies on the ground. It's easy enough to fix for things like the doors where, once they are aligned, the colliders will rest flat on the ground but there's no easy solution for objects like SUV_Quarter Panel Front Left_DEST etc where the colliders form a more complex shape which under some rotations will sit on an edge or a point.

    I've tried lifting the sleep threshold but, while the object's net movement is near zero, it's vibrating too rapidly to go to sleep for even quite large threshold values. I also tried playing around with the Default Contact Offset to try to cure the jitter but it had no discernible effect. I could perhaps script them to go to sleep if their movement over a given time period is sufficiently low but I'll wait until I have my own models and see if it's needed.

    I've lifted the mass of all the prefabs but that shouldn't be having an effect. I've also made the roof top a seperate destructible prefab and that was causing a problem with sleeping until I realised that the mesh was considerably offset from the transform centre and thus my newly introduced rigidbody was sitting outside of the collider for the object.

    I'll be interested to see what you find. I haven't been able to find anything online about compound colliders and sleeping or instability.
     
    Last edited: Sep 24, 2018
  14. RunSwimFly

    RunSwimFly

    Joined:
    Mar 2, 2011
    Posts:
    34
    Just wrote this and it seems to put the compound colliders I've tried it on to sleep nicely. It doesn't consider rotational motion in deciding whether to put an object to sleep but works well enough for my debris. Doubt it adds much overhead but for the moment I'm only attaching it to problem objects. I plucked the values for the constants out of the air. They can be tuned to taste.

    Code (CSharp):
    1. public class CheckSleep : MonoBehaviour {
    2.  
    3.     private Vector3 savedPos = Vector3.zero;
    4.     private int stationaryCount = 0;
    5.     const float distanceSquared = 0.2f;
    6.     const int maxCount = 20;
    7.  
    8.     void OnEnable()
    9.     {
    10.         stationaryCount = 0;
    11.     }
    12.  
    13.     void FixedUpdate () {
    14.         if ((transform.position-savedPos).sqrMagnitude<distanceSquared)
    15.         {
    16.             if (++stationaryCount>maxCount)
    17.             {
    18.                 GetComponent<Rigidbody>().Sleep();
    19.                 stationaryCount = 0;
    20.             }
    21.         }
    22.         else
    23.         {
    24.             savedPos = transform.position;
    25.             stationaryCount = 0;
    26.         }
    27.     }
    28. }
    29.  
     
  15. detvog

    detvog

    Joined:
    Dec 23, 2017
    Posts:
    8
    Hello,
    i work with the last invector and destroyit. The scripts vDestructibleCollider,vDestructible works for shooters goot, but i can not use the sword and the axe for destroy objects. Have anyone a script where i can use sword and axe too?
    Sorry for my bad english. I'am not good in english and i'am not a progammer.
     
  16. DeadlyAccurate

    DeadlyAccurate

    Joined:
    Apr 2, 2013
    Posts:
    186
    Did you see this video where we use Invector and DestroyIt with a sword?


    Does that still work? It's possible that Invector changed something and we need to update our instructions.
     
    ftejada likes this.
  17. DeadlyAccurate

    DeadlyAccurate

    Joined:
    Apr 2, 2013
    Posts:
    186
    Version 1.10 has been submitted to the asset store. The newest feature for DestroyIt: Destructible terrain trees!



    Now you can use Unity's terrain system to paint fully-destructible trees onto the terrain. It works with both Unity's tree system and SpeedTree.



    You can also find a PDF of written instructions here: http://www.modelshark.com/Content/DestroyIt-Destructible-Trees.pdf

    Another new feature is auto-deactivate, when you have thousands of destructible objects in the scene.


    NOTE: This is a major update! Please backup your project before importing!

    Changelog:

    Major Features
    • Support for destructible terrain trees.
    • New Auto-Activate feature on DestructionManager script allows you to have thousands of deactivated destructible objects in the scene and activate them when player is near.
    Unity Version
    • Updated DestroyIt to Unity 2018.3
    Enhancements/New Features
    • Blast effects (rocket, nuke, various explosions) now apply damage using both BlastForce and BlastDamage parameters instead of only BlastForce.
    • Rocket and Explode scripts modified so they have three blast radii - Point Blank, Near, and Far. You can adjust the damage and radii of all three.
    • Added new SpawnObject script to spawn particle effects directly from the object pool.
    • Improved the way AutoPooling works - Destructible scripts insert objects into the pool instead of the ObjectPool looking for Destructibles in the scene.
    • Implemented auto backup/restore process for terrainData tree changes in the Unity Editor if Unity crashes.
    • Implemented process to save destructible tree stand-ins to a hashed Resources path so you can manage destructible drees for multiple scenes without conflict.
    • Hit points of destructible objects can now have decimals.
    • New menu option Window -> DestroyIt -> Setup - First Person Controller adds a first person controller gameobject with camera and pre-configured weapons to your scene.
    • InputManager was moved from the GameManager to the FirstPersonController prefab.

    Particle Effects
    • Added LeafBulletHit, LeafParticleEffect, and LeafParticleEffectHeavy.
    • Updated all particle effects to use the 2018.3 particle shaders.
    Bug Fixes
    • Fixed DestroyIt Mobile shader to correct an error reported in the console, and to fix the progressive damage texture.
     
    Last edited: Jan 3, 2019
    Shodan0101, led_bet and Arganth like this.
  18. teamkamakiri

    teamkamakiri

    Joined:
    Jun 24, 2017
    Posts:
    4
    After updating to the latest version, problems occurred when used with other assets. The menu bar does not update and an error appears in play mode.(No errors are displayed on the console)
    Unity 2018.2.20f1 & 2018.3.0f2
     
  19. DeadlyAccurate

    DeadlyAccurate

    Joined:
    Apr 2, 2013
    Posts:
    186
    Did you delete your old version of DestroyIt and import a fresh version? That may be the reason for the missing menu bar item.

    When you say an error appears in Play mode, can you clarify or provide a screenshot?
     
  20. teamkamakiri

    teamkamakiri

    Joined:
    Jun 24, 2017
    Posts:
    4
    If I install this asset and some other asset into an empty project, it will be in this state. It does not matter the order. Both assets are not updated in the menu bar display.
     

    Attached Files:

  21. zangad

    zangad

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

    We recently had a couple questions about integrating DestroyIt with Opsive's Ultimate Character Controller. We had previously done a video tutorial for integrating DestroyIt with UFPS, but due to changes to UFPS Version 2 and Ultimate Character Controller, that video is now outdated.

    Anyway, long story short - the steps to integrate DestroyIt with the newer version of Opsive's controller are different, but actually easier now. UFPS version 2 exposes an OnObjectImpact event that your game objects can listen to and apply damage to the Destructible component as needed.

    I went through the process for making a crate destructible in Ultimate Character Controller/UFPS, and below are the steps, starting at the beginning.

    Steps:
    1) Create a new project
    2) Import Ultimate Character Controller and DestroyIt asset packages
    3) Open the Ultimate Character Controller UFPSDemo scene
    4) Copy the DamageOnImpact script (see below) into your project
    5) Choose an object in the demo scene (such as one of the crates) you want to be destructible
    6) Add the Destructible script to the crate, set its total hit points to 10
    7) Add the DamageOnImpact script to the crate
    8) From the top menu, choose Window -> DestroyIt -> Setup - Minimal
    9) Run the demo scene and shoot the destructible object with the rifle

    DamageOnImpact Script:
    Code (CSharp):
    1. using DestroyIt;
    2. using UnityEngine;
    3. using Opsive.UltimateCharacterController.Events;
    4.  
    5. public class DamageOnImpact : MonoBehaviour
    6. {
    7.    public void Awake()
    8.    {
    9.        EventHandler.RegisterEvent<float, Vector3, Vector3, GameObject, Collider>(gameObject, "OnObjectImpact", OnImpact);
    10.    }
    11.  
    12.    private void OnImpact(float amount, Vector3 position, Vector3 direction, GameObject attacker, Collider hitCollider)
    13.    {
    14.        Destructible destructible = hitCollider.GetComponentInParent<Destructible>();
    15.        if (destructible != null)
    16.            destructible.ApplyDamage(amount);
    17.      
    18.        Debug.Log(name + " hit by " + attacker.name + " for " + amount + " damage.");
    19.    }
    20.  
    21.    public void OnDestroy()
    22.    {
    23.        EventHandler.UnregisterEvent<float, Vector3, Vector3, GameObject, Collider>(gameObject, "OnObjectImpact", OnImpact);
    24.    }
    25. }
    Results:


    Hope that helps anyone looking to use DestroyIt with Opsive's Ultimate Character Controller (or other controllers - my understanding is they all use UFPS version 2).
     
    NathanielAH, Malbers and thorikawa like this.
  22. DeadlyAccurate

    DeadlyAccurate

    Joined:
    Apr 2, 2013
    Posts:
    186
    Over in the console, press the red stop-sign looking button on the far right. You're getting a compiler error, and if you press that button, it should tell you exactly what script it's in and what line number.
     
  23. teamkamakiri

    teamkamakiri

    Joined:
    Jun 24, 2017
    Posts:
    4
    I'm sorry, I seem to have erased the red button while I was not aware. There was an error.
    Assets/DestroyIt/Scripts/Managers/TreeManager.cs(215,31): error CS0117: `UnityEditor.PrefabUtility' does not contain a definition for `SaveAsPrefabAssetAndConnect'
     
  24. DeadlyAccurate

    DeadlyAccurate

    Joined:
    Apr 2, 2013
    Posts:
    186
    From your screenshot, it looks like you're using 2018.2. There were some significant changes to how prefabs work in Unity in 2018.3, and this error is caused by that. Can you try to import DestroyIt into 2018.3 and see if you're still getting compiler errors?
     
  25. teamkamakiri

    teamkamakiri

    Joined:
    Jun 24, 2017
    Posts:
    4
    The problem with 2018.3 has been solved. It was caused by importing the sample script"Bomb" introduced in the forums in the past. When deleting it, other errors disappeared.I apologize for the trouble.
     
  26. DeadlyAccurate

    DeadlyAccurate

    Joined:
    Apr 2, 2013
    Posts:
    186
    Glad you were able to get it to work!
     
  27. luniac

    luniac

    Joined:
    Jan 12, 2011
    Posts:
    614
  28. DeadlyAccurate

    DeadlyAccurate

    Joined:
    Apr 2, 2013
    Posts:
    186
    I use Modo, but you can do it in Blender, 3DS Max, Maya, etc. We have a tutorial that can get you started on cell fracturing in Blender.


    If you want destruction like the way we did the SUV, or like many of the objects in our destructible asset packs, there's no easy way to do it, but the mesh slicing tools built into 3D modeling tools combined with particle effects can go a long way toward making good-looking destruction.

    Here's a free pack we made of destructible assets. https://assetstore.unity.com/packages/3d/characters/destructible-decoratives-119957

    I used cell fracturing for the vases and concrete objects and manually sliced the park bench. I added particle effects on destruction to fill them out when they get destroyed.
     
  29. luniac

    luniac

    Joined:
    Jan 12, 2011
    Posts:
    614
    oh nice i missed that video when checking the channel, thanks for the tip.
     
  30. luniac

    luniac

    Joined:
    Jan 12, 2011
    Posts:
    614
    in the end of the video you mentioned "grease pencil" which gives location specific shattering effects.

    But correct me if im wrong, at the end of the day, from blender you still just export a model composed of pieces.
    In unity, there won't be any special functionality regarding location or special types of fracturing or anything like that.

    All those extra cell fracture features that make things like wood chips and stuff are just fancy ways of slicing up a mesh right?


    Also a final question:
    When swapping to destroyed prefab, the Force applied is based purely on rigidbody interaction, so based on velocity and mass of interacting bullet, cannonball, etc.

    I'm making a VR melee game with a kinematic sword object, so I assume in theory i can do something cool like swinging at a destructible pillar and it will be destroyed with the destroyed pieces being impacted by the force of the sword swing?
     
  31. DeadlyAccurate

    DeadlyAccurate

    Joined:
    Apr 2, 2013
    Posts:
    186
    That's correct.

    I think what you want can be found with the FireAxe and the MeleeArea script in the demo scene. If that's not quite right, let us know, and we'll see if we can figure it out.
     
  32. luniac

    luniac

    Joined:
    Jan 12, 2011
    Posts:
    614
    ok thanks.

    ooh one more question sorry:
    In VR theres a velocity based approach to holding an object, so it is a non kinematic object moved around with velocity.

    I saw in the demo how one pillar falling on top of another or a tree falling on top of the grouped structure causes damage. I assume this is based on the physics engine velocity and mass.

    So technically a velocity based VR controller can cause that same type of damage as well right, in a fully simulated type of way.
     
    Last edited: Jan 10, 2019
  33. DeadlyAccurate

    DeadlyAccurate

    Joined:
    Apr 2, 2013
    Posts:
    186
    We don't have any experience with VR, so it would be difficult to say with certainty. The cannonball might help you answer that. We tried to include most types of ways you can damage an object (explosion, hit scan, rigidbody, etc.) in our test scenario, but if there's something we're missing, we can look into adding it in a future release.
     
  34. luniac

    luniac

    Joined:
    Jan 12, 2011
    Posts:
    614
    ok, thanks again, I'll experiment with it .
     
  35. luniac

    luniac

    Joined:
    Jan 12, 2011
    Posts:
    614
    Hey i was reading documentation and im confused about the difference between Hit Effects and TagIt.
    It seems like they do the same thing, which is to control particle effects on collision?
    TagIt seems to have a bit further functionality like 'power' tag.
     
  36. DeadlyAccurate

    DeadlyAccurate

    Joined:
    Apr 2, 2013
    Posts:
    186
    We needed to separate out the Hit Effects system from TagIt. TagIt still has some uses for things like power and destructible groups, but we use HitEffects for the particle collision effects.
     
    luniac likes this.
  37. tyapichu

    tyapichu

    Joined:
    Aug 11, 2013
    Posts:
    11
    Hello there, can you please help me? I'm trying to create something like animated pillar - a bone with flesh. I'm adding my bone to list of Debris to Re-Parent like in Re-Parenting sample and it works fine. Next i want my flesh to stay on bone like in Chip-Away Debris sample but it doesn't work as i expect. Flesh flies away like before and my bone also flies away. As i understand Chip-Away ignores Re-Parenting. It creates new separated debrises with rigidbodies... or i'm doing something wrong.
     
    Last edited: Jan 11, 2019
  38. DeadlyAccurate

    DeadlyAccurate

    Joined:
    Apr 2, 2013
    Posts:
    186
    Can you email us (modelsharkstudio@gmail.com) a link to your project (or a sample of it) so we can look at it?
     
  39. Panders

    Panders

    Joined:
    Apr 9, 2013
    Posts:
    4


    Is there a fix for the new Invector Shooter and Melee update 1.3? The DestructibleCollider.cs is broken in the lastest Invector update...

    Assets/Invector-3rdPersonController/Basic Locomotion/Scripts/Generic/vDestructibleCollider.cs(2,16): error CS0234: The type or namespace name `EventSystems' does not exist in the namespace `Invector'. Are you missing an assembly reference?

    and

    Assets/Invector-3rdPersonController/Basic Locomotion/Scripts/Generic/vDestructibleCollider.cs(12,53): error CS0246: The type or namespace name `vIDamageReceiver' could not be found. Are you missing `Invector' using directive?
     
  40. zangad

    zangad

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

    Here are the updated instructions for integrating DestroyIt with Invector Third Person Controller v1.3:

    Steps:
    1. Import DestroyIt into your Invector Third Person Controller project.
    2. Import the DestroyIt Scripts for Invector Third Person Controller 1v3 package.
    3. From the top menu in Unity, choose Window => DestroyIt => Setup Minimal.
    4. Add the Destructible script to an object you want to make destructible.
    5. Add the vDestructible script to the same object, and at the same level.
    6. Run the scene. You should be able to shoot the destructible object and destroy it.
    Example: (Cardboard Box)


    Runtime Results: (vShooterMeleeTopDown_DemoScene)
     
  41. Panders

    Panders

    Joined:
    Apr 9, 2013
    Posts:
    4
    So I need to go thru my entire project and add this by hand? I have made a lot of destructibles.... :(
     
  42. zangad

    zangad

    Joined:
    Nov 17, 2012
    Posts:
    357
    No, all you need to do is import the new package (step 2).

    I provided the complete updated steps for all customers who would like to integrate Invector's TPC Controller with DestroyIt.
     
  43. Panders

    Panders

    Joined:
    Apr 9, 2013
    Posts:
    4
    YES!! as usual you guys rock. This was the least painful part of my middleware upgrade!
     
  44. xnooztvfr

    xnooztvfr

    Joined:
    Jul 31, 2013
    Posts:
    7
    Hello,

    How to integrate DestroyIT with Photon, because the cube disappears when I shoot on the cube.
    Your tutorial for Photon does not help me because I can't click on it but shoot well with my weapon on it.

    Can you help me please? :)
     
  45. zangad

    zangad

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

    Are you referring to the tutorial post here? If so, that post is 3 years old (Unity 4.6) and a lot has changed with both DestroyIt and Photon PUN since then, so the instructions probably just need to be updated.

    To help guide our instruction update effort, can you please provide some additional details about your project:
    1. What version of DestroyIt are you using? (current version is 1.10)
    2. What version of Unity are you using? (current version is 2018.3)
    3. What version of Photon PUN are you using? (the current free version is PUN 2 here)
    4. Are you using any additional asset packs in your project?
    5. You mention the cube disappears. What cube are you referring to? I didn't see a demo scene with cubes in the current free version of Photon PUN 2. Are you creating the cube, or using a different demo scene?
    6. Are you getting any errors or warnings in your Console Log in Unity when the cube disappears?
     
    Last edited: Jan 18, 2019
  46. xnooztvfr

    xnooztvfr

    Joined:
    Jul 31, 2013
    Posts:
    7
    Hello, yes, I am referring to this post.
    1. I use DestroyIt 1.9
    2. Unity 2018.3.2f1
    3. Photon PUN 2.4
    4. Yes, I use this for my FPS Project
    5. I'm sending you a video:

    6. I have no errors or warnings.

    Thanks for your reply :)
     
  47. zangad

    zangad

    Joined:
    Nov 17, 2012
    Posts:
    357
    Thanks for the additional information. We've reached out to 314 Arts (publishers of the Modular Multiplayer FPS Engine asset) requesting an asset exchange so we can setup the scenario and reproduce the issue on our end.

    In the meantime, if you are able to send us a link to download your project (modelsharkstudio@gmail.com), we can take a look at it and try to directly troubleshoot the issue. Otherwise, once we have the FPS asset you're using, we'll try to reproduce and debug it.
     
  48. SpaceRay

    SpaceRay

    Joined:
    Feb 26, 2014
    Posts:
    455
    Hello, I really like much your asset and love to see that is kept being updated and getting better with newer features and is getting updated to latest Unity versions

    I have sent by email the Invoice number

    Please I need your help with two things I want to make

    POINT 1 - 2 WALLS CRUMBLING

    I have DestroyIT and want to make that I have 2 walls close the sides of one road, and then when the player car is near from these 2 walls, a 3d model trigger would activate a script that would make the 2 walls crumbling down and break in a similar way as shown on this video



    So the crumbling walls would fall over the road, but have I am sorry I have no idea how to make a script to make this, I thought that I could shoot something to the walls when the triggers the object, but I do not know how to trigger make the trigger and fire something at the walls

    I think and suposse that I would need to make previoulsy the walls fractured meshes as shown on the Cell Fracture video

    POINT 2 - EARTHQUAKE FLOOR BREAKING DOWN

    Please, I want to make an eartquake effect over a floor that should be breaking down and shatter falling down in the same as seen in this video here after minute 1:57



    As you can see here the asfalt breaks in many parts and goes down a hole and I do not know if this could be done using DestroyIT, and is even seen better at minute 2:16. I do not need that the parts go up and down and elevate as in the video, just break all the road and go down.

    I have seen also this asset in Unity asset store but is really very limited
    https://assetstore.unity.com/packages/vfx/particles/environment/earthquake-fx-115749

    POINT 3 - CRUMBLIND DOWN AND DEMOLITION OF A BUILDING

    Also want to know if there could be a way to make a crumbling and demolition of a huge building as shown in this video at 0:40



    Of course that I do not in any way want to make something as super realistic as in the movie, but I do not know what kind of building should I use that would be fractured in 3D software that would make this building demolition effect and without having too much resources and that the DestroyIT software could handle it

    Thanks really very much for any possible help

    Wishing you all the best
     
    Last edited: Jan 23, 2019
    zangad likes this.
  49. zangad

    zangad

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

    Thanks for reaching out to us and providing details of the effects you're trying to achieve. We developed a couple scripts that should assist you or anyone else trying to reproduce this type of "chain destruction" effect.

    The first script is called Chain Destruction. When the Destructible object it's on is destroyed, it checks all adjacent Destructible objects containing the Chain Destruction component and triggers their destruction. And since the destruction is achieved by applying damage-per-second, you also get the benefit of progressive damage textures and damage effects as the objects take damage.

    The script is also configurable. You can control the speed at which objects will be destroyed, the position and amount of force applied to debris pieces, the upward push effect, etc to help you dial in the effect you're looking for.

    ChainDestruction.cs
    Code (CSharp):
    1. using System.Collections.Generic;
    2. using UnityEngine;
    3.  
    4. namespace DestroyIt
    5. {
    6.     [RequireComponent(typeof(Destructible))]
    7.     [RequireComponent(typeof(Rigidbody))]
    8.     public class ChainDestruction : MonoBehaviour
    9.     {
    10.         [Tooltip("The amount of damage to apply per second to adjacent Destructible objects in the destructible chain. This will control how fast objects are destroyed.")]
    11.         public float damagePerSecond = 125f;
    12.  
    13.         [Tooltip("If you would like to apply force on the debris pieces from a specific position point, you can assign a specific Transform location for that here. If you leave this empty, the gameObject's position will be used as the force origin point.")]
    14.         public Transform forcePosition;
    15.  
    16.         [Tooltip("The amount of force to apply to the debris pieces (if any) when they are destroyed.")]
    17.         public float forceAmount = 300f;
    18.    
    19.         [Tooltip("The size in game units (usually meters) of the force radius. A larger force radius will make debris pieces (if any) fly farther away from the force origin point.")]
    20.         public float forceRadius = 5f;
    21.  
    22.         [Tooltip("The amount of upward push exerted on the debris pieces (if any). More upward push can make the force look more interesting or cinematic, but too much (say, over 2) can be unrealistic.")]
    23.         public float forceUpwardModifier;
    24.  
    25.         [HideInInspector]
    26.         public List<Destructible> adjacentDestructibles; // This is a list of adjacent Destructible objects, ones overlapping the trigger collider of this object.
    27.    
    28.         [Tooltip("Set to TRUE to cause this Destructible object to start taking damage at the predefined damage rate (Damage Per Second).")]
    29.         public bool destroySelf;
    30.    
    31.         private Destructible destObj; // Reference to the Destructible component on this gameObject.
    32.  
    33.         private void Start()
    34.         {
    35.             adjacentDestructibles = new List<Destructible>();
    36.        
    37.             // Attempt to get the Destructible script on the object. If found, attach the OnDestroyed event listener to the DestroyedEvent.
    38.             destObj = gameObject.GetComponent<Destructible>();
    39.             if (destObj != null)
    40.                 destObj.DestroyedEvent += OnDestroyed;
    41.        
    42.             if (!HasTriggerCollider())
    43.                 Debug.LogWarning("No trigger collider found on ChainDestruction gameObject. You need a trigger collider for this script to work properly.");
    44.         }
    45.  
    46.         private void Update()
    47.         {
    48.             if (!destroySelf) return;
    49.  
    50.             if (damagePerSecond > 0f)
    51.             {
    52.                 // If you don't care about adding force to the debris pieces, uncomment this code to use a simpler method of applying damage.
    53.                 //destObj.ApplyDamage(damagePerSecond * Time.fixedDeltaTime);
    54.                 //return;
    55.  
    56.                 // Apply damage with force on the debris pieces.
    57.                 Damage damage = new ExplosiveDamage()
    58.                 {
    59.                     DamageAmount = damagePerSecond * Time.deltaTime,
    60.                     BlastForce = forceAmount,
    61.                     Position = forcePosition != null ? forcePosition.position : transform.position,
    62.                     Radius = forceRadius,
    63.                     UpwardModifier = forceUpwardModifier
    64.                 };
    65.  
    66.                 destObj.ApplyDamage(damage);
    67.             }
    68.         }
    69.  
    70.         private void OnDisable()
    71.         {
    72.             // Unregister the event listener when disabled/destroyed. Very important to prevent memory leaks due to orphaned event listeners!
    73.             destObj.DestroyedEvent -= OnDestroyed;
    74.         }
    75.  
    76.         /// <summary>When this Destructible object is destroyed, the code in this method will run.</summary>
    77.         private void OnDestroyed()
    78.         {
    79.             if (adjacentDestructibles == null || adjacentDestructibles.Count == 0) return;
    80.  
    81.             // For each adjacent Destructible object, set DestroySelf to true for its ChainDestruction component, so it will start taking damage.
    82.             for (int i = 0; i < adjacentDestructibles.Count; i++)
    83.             {
    84.                 Destructible adjacentDest = adjacentDestructibles[i];
    85.                 if (adjacentDest == null) continue;
    86.                 ChainDestruction chainDest = adjacentDest.gameObject.GetComponent<ChainDestruction>();
    87.                 if (chainDest == null) continue;
    88.                 chainDest.destroySelf = true;
    89.             }
    90.         }
    91.  
    92.         private void OnTriggerEnter(Collider other)
    93.         {
    94.             // Add the nearby item to the list of adjacent Destructibles.
    95.             var otherDestObj = other.gameObject.GetComponentInParent<Destructible>();
    96.             if (otherDestObj != null && !adjacentDestructibles.Contains(otherDestObj))
    97.                 adjacentDestructibles.Add(otherDestObj);
    98.         }
    99.    
    100.         private void OnTriggerExit(Collider other)
    101.         {
    102.             // Remove the item that is no longer nearby from the list of adjacent Destructibles.
    103.             var otherDestObj = other.gameObject.GetComponentInParent<Destructible>();
    104.             if (otherDestObj != null && adjacentDestructibles.Contains(otherDestObj))
    105.                 adjacentDestructibles.Remove(otherDestObj);
    106.         }
    107.    
    108.         /// <summary>Returns True if there is a trigger collider on this game object. Otherwise, returns False.</summary>
    109.         private bool HasTriggerCollider()
    110.         {
    111.             Collider[] colls = gameObject.GetComponents<Collider>();
    112.             if (colls == null) return false;
    113.             for (int i = 0; i < colls.Length; i++)
    114.             {
    115.                 if (colls[i].isTrigger)
    116.                     return true;
    117.             }
    118.  
    119.             return false;
    120.         }
    121.     }
    122. }
    This next script is called Chain Destruction Trigger and should help with triggering the effect. With it, you can make an invisible area that the player's car runs over, which starts the chain destruction on the road behind (or in front of) the player.

    ChainDestructionTrigger.cs

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. namespace DestroyIt
    4. {
    5.     /// <summary>
    6.     /// This script triggers a chain destruction sequence on one or more Destructible objects that also have the
    7.     /// ChainDestruction component. Put this script on a trigger collider and assign one or more Destructible
    8.     /// objects that have the ChainDestruction component to the ChainDestructions collection.
    9.     /// </summary>
    10.     [RequireComponent(typeof(Collider))]
    11.     public class ChainDestructionTrigger : MonoBehaviour
    12.     {
    13.         public ChainDestruction[] chainDestructions;
    14.  
    15.         private void Start()
    16.         {
    17.             if (!HasTriggerCollider())
    18.                 Debug.LogWarning("No trigger collider found on ChainDestructionTrigger gameObject. You need a trigger collider for this script to work properly.");
    19.         }
    20.  
    21.         private void OnTriggerEnter(Collider other)
    22.         {
    23.             if (chainDestructions == null || chainDestructions.Length == 0) return;
    24.        
    25.             // For each ChainDestruction component to trigger, set its destroySelf flag to True.
    26.             for (int i = 0; i < chainDestructions.Length; i++)
    27.             {
    28.                 if (chainDestructions[i] == null) continue;
    29.  
    30.                 chainDestructions[i].destroySelf = true;
    31.             }
    32.         }
    33.  
    34.         /// <summary>Returns True if there is a trigger collider on this game object. Otherwise, returns False.</summary>
    35.         private bool HasTriggerCollider()
    36.         {
    37.             Collider[] colls = gameObject.GetComponents<Collider>();
    38.             if (colls == null) return false;
    39.             for (int i = 0; i < colls.Length; i++)
    40.             {
    41.                 if (colls[i].isTrigger)
    42.                     return true;
    43.             }
    44.  
    45.             return false;
    46.         }
    47.     }
    48. }
    And finally, here's a video that ties it all together and shows how the components interact with each other and the destructible objects in the scene to create a (very simplistic) bridge or building being destroyed by a chain reaction.


    We'll be including this feature in future versions of DestroyIt with a demo scene similar to what you see in the video. However, we will also email you a link where you can download the project we used to make the video, so you don't have to set it up yourself and so you can play with it to see how it works. Anyone else who wants the sample project is also welcome to it - just email us your Invoice Number for DestroyIt to modelsharkstudio@gmail.com and we'll send you a link.

    Hope that helps! :)
     
    Last edited: Jan 29, 2019
    AthrunVLokiz likes this.
  50. spencercoulon

    spencercoulon

    Joined:
    Aug 1, 2018
    Posts:
    1
    I was wondering if there's any documentation on how to setup the wood tower found in the example scene? There's a lot going on there, and I'm having a hard time reverse engineering it. I find the included PDF explains to me what things are, but I'm having a hard time figuring out how to implement them. Admittedly I am fairly new to Unity, so I might be overlooking something obvious... but can someone point me in the right direction? Thanks in advance for your help!
    -Spencer