Physics With Unity?
Asked Answered
M

2

0

I want to start adding physics into my game. for an example if i make a cube and extend it so it is in the shape of a normal building, then i shoot something at it i want a part of that building i shot to fall off but keep the building standing unless it falls due to gravity. if you guys can help that would be awesome thanks.

-Christian

Mastoidectomy answered 25/8, 2023 at 11:50 Comment(0)
T
0

Unity does have a ton of pre built in physics operations:

http://unity3d.com/support/documentation/ScriptReference/Rigidbody.html

http://unity3d.com/support/documentation/ScriptReference/Physics.html

But for something like what you are describing as far as I know you would have to build your building knowing that it is going to be destroyed. It will have to be built with this fact in mind in order to collapse properly. And example would be perhaps each separate piece of the building is simply “waiting” to be hit by something tagged with “explosive” and when that does happen that piece becomes effected by physics and falls off, and when enough of your building is “destroyed” larger portions collapse.

If unity does have something built in that could specifically make a collapsing building easier though I am unaware of it.

Thill answered 6/6, 2023 at 1:12 Comment(1)

You're right: physics can't do that, unless you create your whole building with rigidbody bricks - not an efficient thing, for sure. The alternative is to create the building with several "breakable" pieces, like you've suggested. Better yet, a "healthy" model could be used most of time, being replaced by the "breakable" version on the first hit.

Ranique
M
0

I agree with the answer above but elaborate.

I understand two methods to do this.
The first, create a building from “stuff” and then have it fall apart; as can be seen in these two youtube videos.

http://www.youtube.com/watch?v=tpuGkXWBl3M&feature=related
and
http://www.youtube.com/watch?v=OZ9C19-jY98&feature=related

The second is a “cheap knockoff” of the methods used battlefield bad company 2.

They create buildings from prebuilt models of walls and floors. When the wall or floor has suffered enough “damage”, the engine creates some smoke and particles and replaces the wall with a prebuilt model of the wall with a hole in it. You can see proof of concept of this technique used in unity here: http://www.youtube.com/watch?v=qyfTnGzsHJk

You will also find a series of well written comments on the topic under the video.

In BFBC2, when the building suffers enough damage to collapse, the “bare bones” damaged building get swapped for a set of models jointed together and then allowed to gracefully collapse, just like the first videos.

Here is a video or some particularly team unfriendly play in BFBC2. Building collapse at Battlefield Bad Company 2 Building Destruction - YouTube
Skip to about 1:16 to see the engine blow out all the remaining undamaged walls and switch the building model to a collapsible set of objects. It is significantly more impressive than I describe, and also this video shows, in game. First you hear a sound of twisting metal and concrete and the players camera begins to shake. You get out quick after the first time of being crushed by a roof.

Both of these techniques require extensive work to setup but you could re-use that work in subsequent programs, even within the same work.

There are many other cheats that can be performed if the user would not be able to get close to the object. You could even investigate breaking a building mesh up into parts for the physics engine to tumble ground-ward, this technique is described in the contents of the 3rd youtube link. Performing operations on a mesh like that could be quite computationally intensive and may take longer than the gap between frames to perform. I believe that is why a AAA game like BFBC2 would utilize the smoke and mirrors of subtle swapping in explosion smoke. I have not witnessed BF3 building destruction first-hand but I imagine it would mix BFBC2 with those wall/floor prefab swaps accompanied by physical rubble.

Mastoidectomy answered 6/12, 2011 at 1:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.