Search Unity

Destructible 2D ☄️ Dynamic Sprite Destruction

Discussion in 'Assets and Asset Store' started by Darkcoder, May 29, 2014.

  1. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    D2D does use the MeshRenderer to render the objects. However, replacing the mesh like you describe would not be possible. If you can convert your polygons to a rasterized image then it could be used though.
     
  2. Veccu

    Veccu

    Joined:
    Aug 27, 2013
    Posts:
    6
    I just bought and downloaded this asset and there is no more Scene folder under Examples folder as seen in this video:
    .
    At least that car example seen in above video is what I am really missing.
     
    Last edited: Mar 1, 2016
  3. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    The example scenes have been moved to the 'Destructible2D/Examples' directory. The car scene was part of an older version of Destructible 2D, however, I recently remade it and it will be included in the next version which is currently under review. In the mean time I sent you an early copy of this version, check your messages.
     
  4. Bamboy

    Bamboy

    Joined:
    Sep 4, 2012
    Posts:
    64
  5. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    These warnings have been fixed in version 2.0.5 which is still under review. I sent you an early copy of this, check your messages :)
     
  6. MattBatchelor

    MattBatchelor

    Joined:
    Feb 28, 2016
    Posts:
    2
    Hi,

    I am trying to use a custom swipe to split mechanic for mobile devices, but I can't seem to get it to work with the D2D SliceAll function.

    It is more of a fruit ninja style slicing in that it it's colliders are updated every frame as opposed to splitting upon releasing, so that the splitting will be live. Is there anything you can suggest to make this work? Is there a different function that D2D has that would be more appropriate?

    Thanks in advance
     
  7. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    I'm not exactly sure how Fruit Ninja works, but based on your description you might want to create a 2D box trigger (or group of them) under the finger. Then when a fruit enters a trigger you slice it based on the slice shape, and mark the fruit in some way so it doesn't keep getting sliced by the same finger. Right now there is no built in method to slice a single D2dDestructible (e.g. a Slice method), but if you look at how SliceAll works, you should be able to make the required changes.

    In the next next version of D2D I'll add this method, and maybe a demo scene showing you how to implement this kind of game mechanic.

    Also, if you haven't implemented this finger dragging feature yet then you can check out the LeanTouch library in my signature, it has a demo scene for something similar.
     
  8. adam5

    adam5

    Joined:
    Feb 27, 2015
    Posts:
    1
    Hey,

    I am working on a turn based game with destructible terrain using edge colliders. Is there a way to efficiently purge the scene of tiny terrain pieces? Trying to avoid a situation where the player leaves almost invisible pieces of terrain that can still be interacted with.

    Thanks
     
  9. trudeaudm

    trudeaudm

    Joined:
    Apr 17, 2013
    Posts:
    116
  10. digitalThorns

    digitalThorns

    Joined:
    Apr 7, 2014
    Posts:
    8
    I just purchased this asset after importing it seems all of the examples are broken. I'm using Unity 5.3.2, do the examples work for other people? This is what I see


     
  11. MattBatchelor

    MattBatchelor

    Joined:
    Feb 28, 2016
    Posts:
    2
    Thank you very much! I will give this a go today
     
  12. enzoravo

    enzoravo

    Joined:
    Jun 25, 2013
    Posts:
    284
    hello, i'm interested in buying this plugin, but i need to know if it will work in the way that i want.

    i have a platform and i want the platform to be destroyed from the bottom to the up, can this plugin allow me to make this effect ?

    the destruction can be triggered for example when the player is on the platform?

    sorry for the question but i want to be sure the plugin will fit my needs.
     
  13. BabyDinoHerd

    BabyDinoHerd

    Joined:
    Mar 27, 2014
    Posts:
    21
    Hi,
    To follow up on this question, if I'm currently using quad and MeshRenderer with a custom shader that determines the transparency in the shader (simple example would be a circle where I test the radius from the uv values), would this asset not work? Even if it wouldn't work out of the box, could the fracturing/slicing routines be used to break up the quad mesh and re-set the uv's appropriately, and I could just re-use the same shader after that?
    Thanks!
     
  14. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    This is currently only possible if your destructible is splittable, because detecting these small 'islands' isn't such an easy task. However, I have some ideas for how to greatly optimise this feature so it can work with larger terrains and solve the issue you describe. I can start experimenting with this code next week or so.


    As I said in the email, this looks like your files are corrupted. You should try deleting and redownloading the actual Destructible2D.unitypackage (not just the files in your project). If that doesn't work then maybe reinstall Unity.


    Yes this can be done, but if you want it to fall from the bottom in sequence (e.g like in many platform games), then you'll have to manually define the shape of each broken part, or modify the fracturing component to work a little differently. If this the only feature you need then it might be best to just split your platform into predefined pieces and handle the breaking by just adding rigid bodies to each part in sequence though.

    With a little modification you can use any custom shader with D2D, but the collision and fracturing system has no knowledge of this, so if your shader has a custom transparency output then this will be ignored. So as before, you should first rasterise or bake all transparency data first.
     
  15. Mattstg

    Mattstg

    Joined:
    May 5, 2014
    Posts:
    5
    Hello, Recently bought your asset. So far everything is pretty great and loving it. But do you have an available demo of your density scene you were using in the demo? I am having an issue replicating what you have built
    So in my scene, I have a weapon that powers up, the longer it does, the stronger, therefore break through denser walls. But instead it seems to stamp out some, and make other parts of it semi-transparent. Is there a method where I could imitate what you have in the demo and just have a bigger or smaller hole depending on the firepower, without any alpha transparencies on the remaining parts?
    I've been trying to map the Stamp to Density ratio to figure out how much is needed to create a hole, it seems ~1 stamp : 60 density. But through testing and looking at formula, its obviously a non-linear relation. What would be the best method to calculate the amount of firepower to break a specific density?
    I assume a stamp texture with a dark center getting lighter as it reaches the edge would help this effect be more realistic as well?
    Thanks, let me know!
     
  16. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    The DensityTex works by multiplying the brush strength before it's subtracted from the AlphaTex, and the AlphaTex works by treating above 50% opacity pixels as solid, and the Sharpness setting works by separating values above and below this threshold.

    This means that a 50% DensityTex hit by a 100% stamp will cause the AlphaTex to be at exactly 50%, and render transparent. This also means that values near 50% will also be transparent depending on the Sharpness value. So in practice you should try avoiding situations where the AlphaTex can be damaged near this mid value.

    I've considered changing the DensityTex implementation so that it works as a threshold, as this might give better visual results. If you're familiar with C# then you could try implementing these changes yourself, as I'm currently away from my PC and can't experiment with this for at least a few more days.
     
  17. ExcellS23

    ExcellS23

    Joined:
    Sep 22, 2015
    Posts:
    9
    Can you please provide an example of splitting an object in half upon a Trigger Enter? Would it be something like this?:

    void OnTriggerEnter2D(Collider2d other)
    {

    if (other.gameObject.tag == "Enemy1") {

    other.GetComponent<D2d....>().....(Not sure after this)

    }

    }
     
  18. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    The easiest way is to add the D2dQuadFracturer component to your destructible object and then call Fracture() on that component.
     
  19. Mattstg

    Mattstg

    Joined:
    May 5, 2014
    Posts:
    5
    Thanks, the code makes more sense now, saving the alpha is a pretty neat way of saving the dmg on individual pixels, incredible. The game I am making just requires a more simplistic destruction. If an object does (X*explosionStampTextureAlpha) dmg and if dmg > (destructible.defense*destructible.densityAlpha) it will create the hole, otherwise not. (and maybe, internally lower Y.destructibleObject.defense,manually via a separate script), I will look into it soon, as I too won't be able to work on it much before ~2 weeks.
    Thanks for the quick response
     
    Darkcoder likes this.
  20. trudeaudm

    trudeaudm

    Joined:
    Apr 17, 2013
    Posts:
    116
  21. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    If this asset can rasterise the SVG to a Texture2D or Sprite then yes.
     
  22. DrKucho

    DrKucho

    Joined:
    Oct 14, 2013
    Posts:
    140
    hello im unable to make the outline shader work , either does nothing or all the sprite goes black, it might be because the scale of my sprites, i work with 1 pixel per meter , so maybe the outline that is being created is too big that fills all in black?
    don't know but i am also working with an older version of D2D so i wonder if the new versions that you added recently have this shader modified so it might work in my case?
     
  23. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    The latest version of D2D includes an example of how to use the outline effect. Basically, it's designed to work like a Signed Distance Field (SDF) outline effect. This means for it to work your destructible object needs to have some smooth gradients between solid and transparent (in the AlphaTex) for the outline to show, and you need to tweak the Sharpness a bit. I think the shader is a bit hard to use, and may not be so useful in most projects, but I merely added it as this style of outline is basically free with the way D2D works.
     
  24. DrKucho

    DrKucho

    Joined:
    Oct 14, 2013
    Posts:
    140
    Ouch, thats why it doesnt work for me, my alpha texts are "binary" pixeles are full solid or full transparent
     
  25. Bit9Labs

    Bit9Labs

    Joined:
    Mar 24, 2013
    Posts:
    9
    I downloaded this plug-in and am playing with the demos. I am looking at the Red Explosion prefab and I want to change the stamp. In the unity editor/inspector, there is no field to change the texture2d. Is this a known bug?

    I see it in the code:
    [Tooltip("The shape of the stamp")]
    publicTexture2DStampTex;

    But not the inspector:
    Screen Shot 2016-03-15 at 12.09.03 PM.png
     
  26. Bit9Labs

    Bit9Labs

    Joined:
    Mar 24, 2013
    Posts:
    9
    Of course as soon as I ask I figure it out...
    Updated OnInspector() to include:
    DrawDefault("StampTex");
     
  27. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    Oops, thanks for pointing it out!
     
  28. carbonxtreme

    carbonxtreme

    Joined:
    Jan 2, 2016
    Posts:
    1
  29. Fattie

    Fattie

    Joined:
    Jul 5, 2012
    Posts:
    476
    @Darkcoder Hi Carlos,

    We currently use SpriteSlicer which as you know is an excellent but simpler package than the awesome DESTRUCTIBLE2D

    The reason I'm using SpriteSlicer is it works perfectly with 2DToolkit sprites.

    (Notice here for instance I was discussing it with the dude.)

    2DToolkit is critical for many projects where you have complex sprite sheets, differing targets, and other problems.

    Am I correct that you do not currently support 2DToolkit sprites .. would you consider throwing it in??

    I believe it's a pretty modest modification. I especially want to use your explosion algorithm in a project, I mean this very nice algorithm of yours...


    please let me know what you think! cheers!
     
  30. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    If that asset uses SpriteRenderers then sure, though I imagine it would look strange when you destroy isometric sprites in a standard 2D way.


    I don't have 2D Toolkit, and since releasing Destructible 2D a few years ago only 2 or so requests have been made to add support for it, so I don't think there's enough demand to justify the time required to familiarize myself with its system, support it, and maintain support.

    Assuming 2D Toolkit ultimately renders using the MeshRenderer, and your physics are handled with Unity's 2D colliders, then I don't see why the two wouldn't work fine alongside each other already. Since each destructible object needs its own unique destructible texture data, they're not batched together, so it's not like you'd gain much by integrating the 2DTK atlas system.
     
  31. Fattie

    Fattie

    Joined:
    Jul 5, 2012
    Posts:
    476
    Hi @Darkcoder , thanks for the prompt reply, "2D Toolkit .. so I don't think there's enough demand to justify the time required"

    Fair enough - thanks. Let me ask you this. (Sorry if this has already been addressed - yours is a popular product with a lot of forum!)

    Say I have some PNGs as live resources. So I am downloading from the net a.png, b.png, c.png and so on. They're all a known size, 500x500 say, the size is fixed and unchanging in all cases.

    I want to do the awesome effect of your package which I mention in my post above with the example image.

    What's my workflow there, is it possible with the awesome Destructible2D ?! Again sorry if you've explained this a thousand times! :)
     
  32. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    To make a destructible object from a downloaded .png, you'd first have to convert it into a Texture2D, then make a new GameObject, then add the D2dDestructible component to it, then call the ReplaceWith(yourTexture2D) method on this component, and it should now be destructible. Then you just need to add the collider components you want, change the scale to something sensible, etc.

    I believe the effect you're referring to in that image is the impact explosion, which isn't in the current version, but you can easily add it by making a component that has the OnCollisionEnter2D message, and then spawns an explosion prefab at the hit point.
     
  33. Fattie

    Fattie

    Joined:
    Jul 5, 2012
    Posts:
    476
    HI @Darkcoder , thanks, so we're on the same page you mean I would call your call ReplaceWith(), correct?

    For the effect in question, you're saying I should use one of your "explosion prefabs" (and of course trigger it myself however I wish).

    Would you mind telling me, in your system do I have to have a collider on the object? (Some slicing systems indeed work by using the collider in the algorithm.) Or can it just be any old plain Sprite if I wish? (Again sorry there's a lot of forum here, so I couldn't immediately find the answer.) Thanks!
     
  34. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    Yes, ReplaceWith is the method you use to reset the destructible object to the default state.

    For the explosion you don't have to use an explosion prefab, that's just the easiest way to do it. You can just call D2dDestructible.StampAll() to just cut out parts of all destructible objects in the scene, and handle the visual effects yourself.

    You don't have to use colliders, that's just the easiest way to find the location where two objects hit so you can cause visual damage there.
     
  35. Fattie

    Fattie

    Joined:
    Jul 5, 2012
    Posts:
    476
    Hi @Darkcoder,

    "You can just call D2dDestructible.StampAll() to just cut out parts of all destructible objects in the scene, and handle the visual effects yourself."

    Say i have an object "tank" which is a `D2dDestructible`. Say I want to explode only that object (I do not want to explode all D2dDestructible in the scene). Is there a call to tank.GetComponent<D2dDestructible>() which explodes only that one D2dDestructible ?

    TBC I can see you have a cool system, where, people can click on the scree and your scripts (on the camera?) determines the click and results in an object being exploded. I do not want to use that, I will trigger the explosions myself.

    Also, regarding your alpha system which I am just figuring out, "convert (your PNG) into a Texture2D, then make a new GameObject, then add the D2dDestructible component to it, then call the ReplaceWith(yourTexture2D) method on this component, and it should now be destructible."

    In fact , my image has a large transparent area around it: in fact should I somehow set the "sprite" field rather than the "replaceWith" field ?

    Thanks!
     
  36. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    If you look at the 'Explode' demo scene, you can see that it uses the D2dClickToExplode.cs script to fracture the destructible object you click, and also spawn an explosion prefab there. If you look at the code for this, the most important line is: D2dQuadFracturer.Fracture(destructible, FractureCount, 0.5f, 1);

    So just replace the 'destructible' there with your GetComponent call, and set FractureCount to something, and it should work.


    You can call ReplaceWith using a Texture2D or a Sprite. If you look at the inspector for the D2dDestructible component, you can see that you have the option to set both, so you can see what happens there. If you're concerned about this large transparent area then you can either trim it out yourself, then call ReplaceWith, or you can let D2D do it by calling yourDestructible.TrimAlpha().
     
  37. Fattie

    Fattie

    Joined:
    Jul 5, 2012
    Posts:
    476
    @Darkcoder

    I was able to create destructibles on the fly quite nicely like this

    Code (CSharp):
    1. {
    2. Texture2D aPhoto = .. supplies a Texture2D();
    3. // it's 256x256 in my case
    4. destructible.ReplaceWith(aPhoto);
    5.  
    6. // destructible.TrimAlpha();
    7. destructible.HalveAlpha();
    8. destructible.HalveAlpha();
    9.  
    10. // set the height of the destructible...
    11. // "Keep in mind that Texture2Ds have no size information,
    12. // so they will be treated as 1 pixel = 1 unit."
    13. // so for us...
    14. destructible.transform.localScale = new Vector2(1f/768f, 1f/768f);
    15.  
    16. Renderer r = destructible.GetComponent<Renderer>();
    17. r.sortingLayerName = "projectiles";
    18. r.sortingOrder = 0;
    19. }
    20.  
    I then blow them up when relevant in the game like this ...

    Code (CSharp):
    1. {
    2. destructibleHandler.transform.parent = transform.parent;
    3. destructible.transform.parent = transform.parent;
    4.  
    5. D2dQuadFracturer.Fracture(destructible, 7, 0.8f, 1);
    6. }
    7.  
    I then had a simple handler, for OnEndSplit(List<D2dDestructible>), like this...

    notice I wanted to add force heading outwards from the original center:

    Code (CSharp):
    1. public void FireworksStyleFragments(List<D2dDestructible>frags)
    2.   {
    3.   int k=0;
    4.  
    5.   Vector2 nominalCenter = transform.position;
    6.  
    7.   foreach(D2dDestructible d in frags)
    8.     {
    9.     return;
    10.    
    11.     Rigidbody2D r = d.GetComponent<Rigidbody2D>();
    12.    
    13.     r.isKinematic = false;
    14.     r.gameObject.name = "part " + r.ToString();
    15.     r.gravityScale = 0.85f;
    16.    
    17.     Vector2 ctr = d.GetComponent<Renderer>().bounds.center;
    18.     Vector2 forceDirection = ctr - nominalCenter;
    19.    
    20.     // "fireworks" like effect ... rigidbody gravity should be on
    21.     forceDirection = forceDirection * 300f;
    22.     forceDirection = forceDirection + 100f*Vector2.up;
    23.    
    24.     r.AddForce(forceDirection);
    25.    
    26.     if (5.Sometimes())
    27.       {
    28.       r.angularVelocity = 900f.PositiveOrNegative();
    29.       }
    30.    
    31.     ++k;
    32.     }
    33.  
    34.   Destroy(gameObject);
    35.   }
    36.  
    It all worked terrific. Unfortunately - it just wasn't performing enough!

    Sad business! I guess I just had too much else going on in the scene.

    I'm thinking the only thing I could do is make a sort of "pre-baked" split sprite offscreen, and then move it in when needed, then apply force. Of course, all the destructions would be the same for each object, but that's OK.

    One question for the record: what is the highest performance "Sharpness" setting. I want low quality, highest performance. Thanks!
     
  38. Fattie

    Fattie

    Joined:
    Jul 5, 2012
    Posts:
    476
    Destructing to ordinary sprites ...

    Guys - say I have a D2dDestructible. And I call D2dQuadFracturer.Fracture and break it in to 8 pieces.

    The result is eight D2dDestructible.

    Is there a way to instead just make eight ordinary Sprites? Would this be a difficult mod?

    It could be much faster .... in many cases you only need that.

    Pls let me know! thanks!!
     
  39. Fattie

    Fattie

    Joined:
    Jul 5, 2012
    Posts:
    476
    Guys in

    public static void Fracture(D2dDestructible destructible, int count, float irregularity, int blurSteps)

    what is the fastest performance for the "irregularity" field ... low or high?

    what is the fastest performance for the "blurSteps" field? thanks.
     
  40. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    I'm currently making quite a lot of code changes for the next version, so I'll see if I can improve the performance of fracturing. The main way to optimize stuff is to reduce the resolution of the Alpha Tex as much as possible, and adjust the other settings to counteract this though.

    Instead of doing 'Vector2 ctr = d.GetComponent<Renderer>().bounds.center;' you can get the current center of the destructible from destructible.AlphaRect.center. So you can store the center before splitting, then compare it to the center after they all get split.


    Sharpness and irregularity have no bearing on performance, so you can set them to whatever you like. Blur steps decreases performance based on how high it is, so 0 is the fastest. In a future version I'll implement anti-aliased fracturing, so this feature will no longer be required.
     
  41. Fattie

    Fattie

    Joined:
    Jul 5, 2012
    Posts:
    476
    @Darkcoder , thanks for this great tip:

    "you can get the current center of the destructible from destructible.AlphaRect.center"

    Also thanks for explaining

    "Sharpness and irregularity have no bearing on performance" "Blur steps: 0 is the fastest"

    Awesome. You know, what I really want to know is. When I split a destructible, say in to eight pieces,

    is there a way to make the result simple Sprites, rather than destructibles?

    Surely in many/most cases that is all that is needed.

    It would seem to be incredibly faster to just make eight ordinary sprites, than eight new destructibles -- I think?

    What do you reckon? Cheers...

    For example, I did an experiment. I took a destructible (about 256.256, with the alpha halved twice) and destructed to eight pieces. I simply kept those under a transform. I then Instantiated that whole transform during gameplay. It does seem to take a long time, jitters. Whereas it's no problem to duplicate 8 small ordinary sprites, I think, during a run.
     
    Last edited: Mar 22, 2016
  42. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    No, because that's not how Destructible 2D works.

    If you just need slicing that works very quickly then I believe the Sprite Slicer asset is more suitable.

    Destructible 2D works by masking the original sprite texture with an alpha map (Alpha Tex), which allows you to cut holes in your object using any texture or shape you like, and even gradually chip away at them until there's nothing left. However, the Sprite Slicer asset works by modifying the mesh used to render the sprite texture, which means you can't do these things, but it does mean you can create perfectly sharp slices in a very efficient way, and you basically get collider data for free.

    The reason why fracturing isn't so fast is because this alpha map data is stored in a large byte array that must get split into 8 smaller arrays, then these arrays must be searched through to find the collider edges. The actual destructible part of it isn't what's slowing it down, simply the requirement of the algorithm to search through these arrays.
     
  43. Fattie

    Fattie

    Joined:
    Jul 5, 2012
    Posts:
    476
    I completely understand, thanks for the explanation. (Actually in my particular setup Destructible2D is faster than sprite slicer and similar solutions! Just not quite fast enough for my particular use case.)

    Again thanks a million for the superb explanation here. Thank you.
     
    Darkcoder likes this.
  44. Eltayeb

    Eltayeb

    Joined:
    Jan 24, 2014
    Posts:
    20
    I bought the plugin today and i'd like to use it with unity 4.7 cause i have a license already for that, can i get an older version that works with it?
     
  45. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    If you enable forum conversations or send me an e-mail I can send you the last build of D2D for Unity 4.
     
    dc likes this.
  46. dc

    dc

    Joined:
    Jul 16, 2012
    Posts:
    9
    I also need the latest Unity 4 build please. I've updated it and now it requires 5.

    You could submit it to the Asset Store as other plugins submit multiple versions ... for example see: http://u3d.as/33d uSecuencer it was submitted with 5 different versions of Unity 4x and 5x "Package has been submitted using Unity 4.6.1, 5.0.0, 5.1.0, 5.1.2, and 5.3.0 to improve compatibility within the range of these versions of Unity."

    Cheers!
     
  47. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    Sent.
     
    dc likes this.
  48. Mattstg

    Mattstg

    Joined:
    May 5, 2014
    Posts:
    5
    Hello Darkcoder, I'm having issues with an object. the line of code:
    "D2dHelper.IsValidUV(stampUV) == true" inside d2dDestructible.cs in Stamp is returning false for an object causing it not to be stamped. I was wondering what sort of scenarios can cause this?

    Notes:
    I am not using the most recent version of D2d because I modified it to preform stamps (Power -vs- Defense) when it exceeds, it does 100% removal of alpha. I have other objects on the scene that work fine, so i don't think it is that

    Object in question:
    The object is strange (but trust me this method is unfortunately required), it does not have a destructible component as part of the prefab, instead during its setup it Adds a d2dPolygonCollider component. (Which then adds the destructible because your awesome setup). Other objects on my scene have a similar setup but they work with the stamp, only this one object (circular) keeps returning the false IsValidUV.
    What scenarios cause this? I got lost at inverse.MultiplyPoint.
     
  49. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    Stamping works by converting your input stamp data (e.g. size, rotation) into a transformation matrix. This matrix is then multiplied with coordinates for each corner of the stamp (0,0, 0,1, 1,1, 1,0) to find the min/max UV that can possibly be painted by this matrix. These UV coordinates are then converted into pixel coordinates, and two loops go through every pixel in this rectangle. Then for each pixel, the coordinate is multiplied by the inverse stamp matrix to find the stamp coordinate of the pixel. Since the pixel rectangle can be larger than the actual stamp (e.g. If it's rotated), this inverse coordinate can go outside of the expected 0..1 range, so that check is used to discard such pixels. If it isn't discarded, then the pixel and stamp values are read, modified, written back, and that pixel is marked as dirty.

    The code for this was greatly improved and simplified in the latest version, so I recommend you upgrade if that's the only modification you made. I don't see any reason why such a modification would cause a issue though, unless you modified the matrix code incorrectly.

    If you still can't get it to work then please PM or email me a simple demo with the modified scripts that I can test.
     
  50. Eltayeb

    Eltayeb

    Joined:
    Jan 24, 2014
    Posts:
    20
    i'm reducing my destructible object scale in run time but when i do that it no longer gets destroyed