Search Unity

Impact Deformable - Dynamic mesh deformation by collision [released]

Discussion in 'Assets and Asset Store' started by L-Tyrosine, Oct 23, 2012.

  1. L-Tyrosine

    L-Tyrosine

    Joined:
    Apr 27, 2011
    Posts:
    305
    Last edited: Mar 8, 2022
  2. PROTOFACTOR_Inc

    PROTOFACTOR_Inc

    Joined:
    Nov 15, 2009
    Posts:
    4,054
    really nice! i guess a nice next step could be speciying the resistance of specific part of an object ( vertex alpha, RGB map, alpha ???) No?
    Great work!! :)
    Edit : maybe i didn't read correctly your desciption : "- Maximum vertex distance from original position can be specified."
    Could you tell how ?
     
  3. L-Tyrosine

    L-Tyrosine

    Joined:
    Apr 27, 2011
    Posts:
    305
    Hi!

    There is a float property at script (MaxVertexMov) that sets maximum vertex deform distance (in object space) from its original position (0 specifies no limit).
    It affects the whole mesh.

    A map to configure resistance for specific parts would be a nice idea, and not too hard to implement.
     
  4. PROTOFACTOR_Inc

    PROTOFACTOR_Inc

    Joined:
    Nov 15, 2009
    Posts:
    4,054
    Then i think you should really consider implementing that since many guys would use this for real time deformation in racing games and cars usually don't deform evenly everywhere, parts are more or less flexible etc... You have a really nice thing here! Keep it up!
     
  5. L-Tyrosine

    L-Tyrosine

    Joined:
    Apr 27, 2011
    Posts:
    305
    Yes, I will definitely implement in next release.
    Thank you!
     
  6. kenshin

    kenshin

    Joined:
    Apr 21, 2010
    Posts:
    940
    Really impressive!

    Bookmarked!
     
  7. Gigiwoo

    Gigiwoo

    Joined:
    Mar 16, 2011
    Posts:
    2,981
    Nice work! Will keep this one in mind. Does it run on mobile devices (iOS/Android)?

    Gigi
     
  8. L-Tyrosine

    L-Tyrosine

    Joined:
    Apr 27, 2011
    Posts:
    305
    There are some flags to tweak deformation process and make it use less CPU power like disabling collider deformation and setting to update mesh and collider only at determined intervals (instead of every impact). So there should be no problem. Also it was tested on XPeria Play (Android) and runs smooth.
     
  9. wccrawford

    wccrawford

    Joined:
    Sep 30, 2011
    Posts:
    2,039
    This is one of those things that makes you wish you had a game to implement it in. Awesome job.

    I don't see a video/webplayer with an object that has a texture, though. They all seem to just be single colors. Does it handle that well, too? (I'd assume so, but thought I'd better ask.)
     
  10. L-Tyrosine

    L-Tyrosine

    Joined:
    Apr 27, 2011
    Posts:
    305
    Thank you!

    Yes. UVs are tied to vertices so it works fine.
    There is a faint texture at cube in the first demo. Lets change it with a test texture:

    $CubeTexture.png
     
  11. L-Tyrosine

    L-Tyrosine

    Joined:
    Apr 27, 2011
    Posts:
    305
    Hi all.

    Just to show another Impact Deformable use case: Hard.Point, built for Ludum Dare game competition #28 and growth to a full project.
    In this game Impact Deformable was used to deform/repair vehicles with damage.

    $Impact.png
     
  12. Hrothvitnir

    Hrothvitnir

    Joined:
    Apr 26, 2013
    Posts:
    109
    This is interesting, are you still working on it at all?

    I would be interested in using this for something like flesh. I'm pretty sure I could figure out how to make it return to its usual shape after impact by looking at your repair function and just making it automatic (maybe, I don't know if that would look right).

    But what about "preserving volume" - for example if something is impacting your object in the X direction it should expand in the Y and Z direction proportional to how much X is being pressed (squish).
     
  13. L-Tyrosine

    L-Tyrosine

    Joined:
    Apr 27, 2011
    Posts:
    305
    Yes, if you keep calling repair each frame the reform process behaves like soft body. This is because its applied by a proportion of current deformation. One could achieve different effects on that matter playing with lerp / smoothdamp.

    Now that's not trivial... Volume involves integral calculus and lot of heavy work on tuning it to be real time.
    I've been reading some alternatives like described here http://research.microsoft.com/en-us/um/people/chazhang/publications/icip01_ChaZhang.pdf but not tested it yet.
     
  14. Hrothvitnir

    Hrothvitnir

    Joined:
    Apr 26, 2013
    Posts:
    109
    Interesting. But I guess for my needs, and most users I would imagine, a very simple approximation - or even just faking it somehow - would be all we need. Maybe something like the hardness map, where we could paint areas (and intensity) that behave inversely (if one direction contracts, the other expands, etc). But maybe that's more complicated than it needs to be, I don't know.
    ..
    My goal is to have a fat blob of a monster that can press flat against things, or squeeze through tight spaces believably - but I can also think of a number of interesting ways to use this...
     
    Last edited: May 16, 2014
  15. L-Tyrosine

    L-Tyrosine

    Joined:
    Apr 27, 2011
    Posts:
    305
    I see. The repair function let you specify (optionally) the point and area to apply reformation so one could set it to other side of mesh (since from impact point) calculated by ray casting - that way, if you call it in the same time that deformation happens on the other side of the mesh you could get *somewhat* the rubber/squeeze effect, maybe it would look really cool on high detailed meshes but honestly is hard to predict.

    You can specify a hardness map but is designed to let you specify softer and harder pieces on mesh by a control texture... What you suggest would be nice but then again not trivial.

    So here we are talking also about collider deformation (the monster must update its collider to squeeze like that and it must be mesh collider)... This is possible and working out of the box with Impact Deformable but a high CPU usage is involved (PhysX).

    All in all, Impact Deformable works best with Rigid Body deformation (it was built for this after all). It can be tweaked and customized to simulate some of effects that you described but true is that to achieve 100% of the monster squeezing thing a full soft body/fluid solver would be needed (one that I would love to see in Asset Store).
     
  16. Hrothvitnir

    Hrothvitnir

    Joined:
    Apr 26, 2013
    Posts:
    109
    Oh I understand the concept of the hardness map, I just meant that maybe a similar additional map might help artists tweak the effect we were talking about.

    Hmm, I didn't think about the Rigid Body vs Collider deformation thing. High CPU cost might be acceptable, worst case maybe I would have to limit it to cut scenes or something... but then again we're supposed to get updated, faster PhysX with Unity5 (which I'm waiting for anyway).

    I think I'll buy this anyway and try playing around with collider deformation when I get some free time (maybe in a year or so, haha).
     
  17. L-Tyrosine

    L-Tyrosine

    Joined:
    Apr 27, 2011
    Posts:
    305
    Last edited: Dec 18, 2015
  18. HAMILCAR_TECHNOLOGIES

    HAMILCAR_TECHNOLOGIES

    Joined:
    Dec 14, 2018
    Posts:
    12
    Hi , how can i use this with ontrigger enter ?
     
    L-Tyrosine likes this.
  19. L-Tyrosine

    L-Tyrosine

    Joined:
    Apr 27, 2011
    Posts:
    305
    Hello, I just got your e-mail and answered there with a working example.
    To anyone also needing this:

    Code (CSharp):
    1.     private void OnTriggerStay(Collider other)
    2.     {
    3.         // Get the impact deformable on object we are colliding with (exit if none)
    4.         ImpactDeformable impactDeformable = other.gameObject.GetComponent<ImpactDeformable>();
    5.         if (impactDeformable == null)
    6.             return;
    7.  
    8.         // Get a Y Align vector of both colliders position
    9.         Vector3 p = transform.position;
    10.         p.y = 0.25f;
    11.  
    12.         Vector3 o = other.transform.position;
    13.         o.y = 0.25f;
    14.  
    15.         // Call deformation process, from this position to collider position, Radius scaled
    16.         impactDeformable.Deform(p, (o - p).normalized * DeformationRadius);
    17.     }
     
  20. HAMILCAR_TECHNOLOGIES

    HAMILCAR_TECHNOLOGIES

    Joined:
    Dec 14, 2018
    Posts:
    12
    Well received , thank you very much for the fast and very helpful reply
     
    L-Tyrosine likes this.
  21. Unknown2002

    Unknown2002

    Joined:
    Jan 18, 2021
    Posts:
    1
    Hello!
    This asset is really helpful and I liked it a lot, I actually saw it in another game which makes me go and buy it :)
    But when I'm trying to attach it to my object that it's have already the mesh filter and collider, even the mesh is enabled read and write. Sadly nothing happens :(
    Thank you!
     
    L-Tyrosine likes this.
  22. L-Tyrosine

    L-Tyrosine

    Joined:
    Apr 27, 2011
    Posts:
    305
    Sure, lets check it.

    So, there is another object colliding with it, right?
    You could try to decrease hardness settings in the Impact Deformable component (maybe the collision is too slow for any effect).

    Please, if you are able to put a breakpoint in the method ProcessCollision() in ImpactDeformable.cs, just to ensure that Unity physics is properly set up.

    You can answer here or e-mail me in the support contact supplied in the manual, I will watch both channels.

    Thank you.
     
  23. kaniballo

    kaniballo

    Joined:
    Sep 2, 2013
    Posts:
    8
    Hi, great asset - (1) basic question - what is right way for stop doing deformation?(at sertan time). Scenario - RollingBall (mainPlayer) stopping doing deform onSelf at collision with 'Environment' - but only with 'Enemy' on CollissionEnter,... at short stop Deform RollingBall with Environment only with Enemy Tag.
    1. enable/desable 'Impact' component seem to not work.
    2. very big Hardness value - give little deformation ( i.e process collision).
    It seem MaxDeformationRadius set to 0.001 do the trick - it's right way?

    ,...and if RollingBall (mainPlayer) - have MeshCollider - what is right way (optimisation) to check for MeshDeformedState - at sertain time?(1sec interval)?
    Tnx again great asset.
     
  24. L-Tyrosine

    L-Tyrosine

    Joined:
    Apr 27, 2011
    Posts:
    305
    Hi!

    There is no built-in method to ignore deformation for a tag or layer but it's trivial to implement it;
    Every deformation in the component starts in ProcessCollision method, just find it in ImpactDeformable.cs and add some condition, like:

    Code (CSharp):
    1.     // Process a collision message from Unity
    2.     void ProcessCollision(Collision col)
    3.     {
    4.         // Ignore deformation with enemy
    5.         if (col.gameObject.layer == LayerMask.NameToLayer("Enemy"))
    6.             return;
    7.         ...
    8.     }
    9.  
    I'm unsure on what you meant by "MeshDeformedState", if you are asking about the StructuralDamage that measures current mesh deformation level, you can call as much as you want for this value is cached, it keeps it's value once calculated till next deformation - so no performance cost.

    Please let me know if you have any more doubts and thanks for using Impact Deformable.