• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by nathaniel · Sep 28, 2010 at 07:06 PM · terrainruntimedeformationmodifydestructible

Implementing destructible terrain, deformable ground, or craters for an artillery game (think scorched earth!)

Hi, I'm fairly new to Unity3d and was wondering how to go about implementing a boolean operation on a mesh equal to the radius of an explosion, or any equivalent effect to ac$$anonymous$$eve a hole in the ground. T$$anonymous$$s is an important element wit$$anonymous$$n artillery games. I have a feeling it will be non-trivial, but any help or a point in the right direction would be greatly appreciated. I am using an imported mesh, but I can switch to terrain if it would be easier to implement.

The relevant questions I found suggested moving each vertex wit$$anonymous$$n the explosion radius outward, but I'm lost on how to do t$$anonymous$$s. I found http://unity3d.com/support/documentation/ScriptReference/Mesh.html , w$$anonymous$$ch is a good starting point, but I need a push in the right direction from here!

Comment
duck
Herman-Tulleken

People who like this

2 Show 0
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by duck · Sep 28, 2010 at 08:27 PM

Because the terrain system uses a heightmap instead of regular mesh data, you can't modify the vertex positions directly.

Instead you have to adjust the values stored in the heightmap using GetHeights and SetHeights.

For a crater, you'd want to reduce the heights of the area nearest the explosion, but raise the heights around the crater's lip. You'd probably also want to modify the texture used at that position on the terrain.

These separate techniques have been described in other answers on t$$anonymous$$s site, so follow these links for more information:

Modifying terrain height under a gameobject at runtime

Modifying Terrain Splat Texture at Runtime

Comment
nathaniel

Herman-Tulleken

People who like this

3 Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image nathaniel · Sep 28, 2010 at 08:42 PM 0
Share

Thank you, I'll try this technique and report back if I have any troubles!

avatar image AdnanMateen88 · Dec 06, 2013 at 02:34 PM 0
Share

the links you have mentioned arnt working anymore ... :\

avatar image AlucardJay · Dec 06, 2013 at 04:22 PM 0
Share

Here are the links :

  • http://answers.unity3d.com/questions/11093/modifying-terrain-height-under-a-gameobject-at-run.html

  • http://answers.unity3d.com/questions/7985/modifying-terrain-splat-texture-at-runtime.html

avatar image

Answer by FilipBaba · Mar 28, 2012 at 08:48 PM

These features of Unity have very little documentation. It took me allot of digging around and experimenting to make a practical deformable terrain. The concept is that Unity terrain stores Height data in a 2 dimensional array [x,y] the height is a float from 0.0 to 1.0 and it can be changed at runtime. To give craters a round concave look we use a texture with an alpha map. We then convert the pixel data from the alpha map into a float ranging from 0.0 to 1.0 depending on how dark the pixel is. Then all that is left is to subtract the crater Height Data from the Terrain Height Data at the impact Vector3 position.

For the textures the process is very similar but it differs in the following way: For every texture you have on your terrain (In t$$anonymous$$s case 2 textures: Grass and Dirt) you must adjust it's alpha value, for example: To get dirt we must make: Grass alpha = 0.0 Dirt alpha = 1.0 to blend grass and dirt we must make: Grass alpha = 0.5 Dirt alpha = 0.5

You can find my implementation here: http://www.youtube.com/watch?v=2W3Vm1_QGf0

Comment
SanSolo

People who like this

1 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Modify a mesh at runtime 0 Answers

Creating similar terrains at run-time 3 Answers

Tips to start underground digging 3D game 2 Answers

How to create destructible tile based 2D terrain like 'Broforce' does ? 2 Answers

Modify a detail mesh healthy/dry color at runtime 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges