Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Destroy only part of object

Discussion in '2D' started by VortexGamer, Jan 8, 2016.

  1. VortexGamer

    VortexGamer

    Joined:
    Apr 27, 2015
    Posts:
    49
    When an explosion hits the planet instead of destroying the whole planet you destroy only part of it.
    Photo examples: BEFORE: PlanetTop.png AFTER: PlanetTopDMG.png
    How to do this?
     
  2. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    Make the planet from segments chilled to an empty game object & just destroy each segment as needed.
     
  3. VortexGamer

    VortexGamer

    Joined:
    Apr 27, 2015
    Posts:
    49
    @tedthebug
    No but The explosions are going to be different so unless I make each object one pixel big, It won't work out, Most of the explosions will be circular...
     
  4. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    If each segment destroyed is going to be different size/shape depending on the explosion that hit it search for assets or tutorials that let you destroy pixels when you dig them. You should be able to modify it so that it works for any pixel contained within the area of the explosion.

    E.g. Look at pixelsurface by @JoeStrout
     
  5. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,848
    Thanks for the plug, Ted! Yep, @VortexGamer, it sounds to me like exactly what PixelSurface (webGL demo; forum thread; asset store link!) was made for.



    If it's not exactly what you're looking for, please let me know how it's lacking, so maybe I can improve it!
     
  6. VortexGamer

    VortexGamer

    Joined:
    Apr 27, 2015
    Posts:
    49
    @tedthebug
    I would do it then but just don't know how to divide it into segments, Any tutorials/Code out there?
    @JoeStrout
    I'm drooling, I just can't afford it!!!
     
  7. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    Sorry, not that I know of. If I really really needed it I'd save & buy the asset or experiment with something like I said if I had time.
     
  8. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,848
    Well if you want to do it yourself, it basically works by writing to a Texture2D. See SetPixels for example. Getting it all to work efficiently is a bit thorny, but you may be able to make a special case that works well just for your game.

    Good luck!
    - Joe