#2D breakable objects

1 messages · Page 1 of 1 (latest)

burnt oracle
normal oracle
# burnt oracle Hey Guys. I want to make the 2D objects breakable after being hit. Is there a re...

there are different ways, but brackeys has a video on how to do something like that in 3d.
what I'd change though, if you want you can keep it like that but with 2d sprites and rigidbodies/colliders instead of 3d ones, but you could also play a sprite sheet animation of it breaking
https://www.youtube.com/watch?v=EgNV0PWVaS8

health system for objects is something different, but if you want you can try a modular health system that you can attach to both enemies and objects that can be destroyed
excerpt from my response here https://www.reddit.com/r/gamedev/comments/re9hmr/designing_systems_in_unity/

Do you want a health system that can be used by different objects in the game, not only a player? Make a health component with a method like InflictDamage(float damage). During collision interactions, you can check if an object has a health component and if so, deal damage if necessary. To further abstract, you can have the health component be an interface instead. One health implementation could just have a health float variable and adjust it when damage is dealt. Another implementation could have damage debuff multipliers or another variable for armor etc. When dealing the damage, you'd only have to query for the IDamageable interface though. The IDamagable could also implement an event that is called when the damage sinks to 0 or less that you can subscribe to.

Let's break some stuff! :D

● Western Props Pack: http://devassets.com/assets/western-props-pack/

♥ Support my videos on Patreon: http://patreon.com/brackeys/

● Fracturing & Destruction Plugin: https://www.assetstore.unity3d.com/#!/content/9411?aid=1101lPGj

····················································································

...

▶ Play video
#

the basic idea is to give your 2d object some kind of health component, deal damage when it colllides with the player projectiles or hurt box (or with enemy projectiles too if you want)
when the object health goes to 0, you can destroy the main object and instantiate a prefab that has the fragments of the destroyed object, optionally you could apply 2d physics forces to the individual pieces then so they fly around
https://docs.unity3d.com/ScriptReference/Rigidbody2D.AddForce.html