# Destoying surface of a Game Object

Hi everybody.
I am new to Unity community and actually this is my first post here. Therefore don’t laugh at me if you find me too rookie.

BTW I have a question in mind which I can not figure out in witch direction I should look for it.

If there is a bullet that is going to have a certain amount of power for destroying the object that is going to have collision with, how can we destroy the surface of that object or some parts of it? For example in case the bullet catches the ground then how can we destroy some of the ground based on the power of that particular bullet?

Can anyone please point me the direction?

Nobody?

Hi aboo and welcome to the forum

You might need to be a little more specific in your question as asking how to deform geometry and/or remove faces from it is a pretty general question to ask, especially if you’re new to Unity.

Well. Thank you for the reply.
It’s looks like that explaining this issue must be a bit more difficult than the solution.
Here is the scenario:
You have two different ball (different size and weight) and a surface (possibly a terrain ? I don’t know). We shoot one ball and it touches the surface of the terrain (or maybe any other Game Object), now what we need is to destroy part of the surface based on the specifications of the ball. If we shoot another ball the destroy area will be different.

For example in Worms2D or Worms3D (if you remember that) when you shoot the ground it creates a hole in the ground (surface).

Please let me know if I need to explain anything else.

With terrains is going to be a pain in the ass to do such thing. By their very definitions terrains are static geometry and that means they do not change during the game time. I am no expert so i don’t know if unity allows you to change static geometry on the fly. There might be a trick with transparent shaders and new objects that look like an impact crater, but this is beyond my actual knowledge.
With objects is a different story, you can model one solid object and several pieces of that object and replace them at runtime when the object is hit. In case of total annihilation of that object you can model recognizable bits of that object and lots of debris and use physics to make the destruction spectacular.

Now coming to the real problem you have: games like movies does not try to copy real life. You do not need to reproduce the smashing effect like in physic calculating where the object is going to crack and in how many pieces, what weight each piece have to know how far away they will fall from the original object. Games are about smoke and mirrors.
You have to create the illusion of an object destroyed, you have to give player brain the suggestion of what is happening. This will be enough for a trained audience to fill in the gaps. And thanks television we are trained enough to recognize such things.

No they aren’t. http://forum.unity3d.com/viewtopic.php?t=11285&start=3 (Otherwise, how would the terrain construction tool in Unity even work.) Also, you can change any regular meshes you like in any way you like using the mesh scripting interface. Keep in mind that this isn’t really a trivial subject though.

–Eric

So you say is wise and does not imply any computational effort to move such enormous amount of data between cpu and graphic card at runtime without any penalty to fps? (lets assume that the average user does not have a cuda ready video card) And i think we are talking here about the result shipped to a customer not about the editor.

PS cant look at your example, i am on windows and my mac is gone.

Enormous amount of data? It’s just a heightmap. Again, how else would the terrain editor work? Keep in mind that results in the editor are normally significantly slower than results shipped to customers either via web players or stand-alones. Also, the terrain tools are just Unity scripts written in C# and obviously work fine in realtime. You can see a web player of my example project here.

–Eric

Thats cool Eric

I am getting some directions.
Eric, please correct me if I am wrong. In the Bomb example you have provided the ground is a terrain object and you are using some scripts to re-position the geometry of the shot area.
That’s cool.
I should put more time on figuring out how to implement such effects.

However I believe this is not going to cover my needs since I need the surface to be in a casual form and not 3D (like Worms2D) and I am not sure if terrains are the answer to my question.

I will update this post if I could find anything.

Isn’t that the same principle as what Eric shows but using a side view rather than a top-down view?

Can be, Geoff.
However I am not sure if we have a 2D object which we are going to look at it from side view so that it looks like a land in 2D, this method works or not. because this land object has no thickness. In Eric’s solution the hole gets deeper and deeper and I doubt if we can see it from the side view.

Anyway, I am not saying that this doesn’t work but I need to test this solution and see the performance for iPhone as well.

I will update this post if I could get to any result.

Indeed I don’t think terrains would work very well for a Worms-like 2D game. Actually I’m not sure Unity is really the best tool for that kind of game if you’re after destructible 2D terrain and so on.

–Eric

If you say so Eric then I believe the case is closed for Unity because I can see in your website that you have a great experience with terrains.

Anyway, do you think we can get better result using TGB?

There is also something else in my mind which I would like to know your idea about it: imaging we have a rectangle with the minimum thickness and we have a circle with same thickness. The rectangle is going to play as the 2D ground and the circle is the explosion area. If we can subtract (like boolean subtraction in 3D Studio Max) the circle from the rectangle on fly in Unity then I guess we are almost done.

Do you think a clipping shader might be the solution as it is described here : http://forum.unity3d.com/viewtopic.php?p=84668&sid=e2bd1018db546714a4cd848926f3c13f#84668

Does the VertexLit Clip Shader affect the rigid and the collision area as well? I guess I need to test it out.

A shader definitely won’t affect anything physical like a collider. I think using 3D in this case isn’t really the right answer. You can actually do destructible 2D in Unity (like the bunkers I did here) but it’s not optimal. Unity is, after all, first and foremost a 3D engine. Some 2D concepts still work quite well in 3D, like moving sprites around, but some aren’t really suited. The main problem being that a texture of any decent size has quite a lot of overhead when uploading any changes to the graphics card.

–Eric

You are right Eric. However I can use advantage of the 3D environment while building a 2D game.

BTW during past days I was thinking that it sounds really weak for Unity that has no “boolean cut on fly” feature. I mean, I can name endless games and actions which need this feature.

Does anyone know if this feature is going to be included in Unity 2.5?

You can always make something like that yourself, keeping in mind that it’s not a simple task.

–Eric

“Something like that” == Unity ?

I really admire Unity, but this feature is really a must have. Don’t you think so?

Just imaging that you have a shooting game, and all you need is to shoot at a wall and make holes in it. I don’t think you can do it with Unity without having the boolean cut feature.

BTW, I am really trying to find a solution since my trial is expiring in 15 days

Not really. I haven’t had any game ideas so far where I would have used it. I’d call it a “nice to have” rather than a “must have”.

Usually putting bullet holes in walls is done with decals. Actually putting physical holes through a wall would potentially massively increase the geometry required.

Like I said, you can do this yourself, using the mesh scripting interface. Granted it would be cool (and a lot simpler) if Unity had this built-in. But you aren’t prevented from doing this if you really want it, even without a built-in feature.

–Eric