Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
0
Question by Hyperion · Aug 24, 2013 at 11:54 PM · javascriptterraindynamicdestructible

DDT script only works on one terrain

Hello Everyone,

I have a dynamic destructible terrain script that works perfectly one terrain I have (the only one in the scene). The purpose of it is to make craters upon collision with my projectile. Unfortunately, when I apply the script to a different terrain inside a different scene, the script fails to work! It is very annoying, as I have fiddled around with the code as much as I could and have not been able to solve this issue. Code:

 private var tData : TerrainData;
 private var saved : float[,];
 var cratertex : Texture2D;
 var xRes;
 var yRes;
 var craterData;
 
 
 function Start () {
     tData = Terrain.activeTerrain.terrainData;
     xRes = tData.heightmapWidth;
     yRes = tData.heightmapHeight;
     saved = tData.GetHeights(0,0,xRes,yRes);
     craterData = cratertex.GetPixels();
 }
 function OnApplicationQuit () {
     tData.SetHeights(0,0,saved);
 }
 function OnCollisionEnter (hit:Collision) 
 {
 if (hit.gameObject.tag=="projectile")
     {
     var x : int = Mathf.Lerp(0, xRes, Mathf.InverseLerp(0, tData.size.x, GameObject.FindWithTag("projectile").transform.position.x));
     var z : int = Mathf.Lerp(0, yRes, Mathf.InverseLerp(0, tData.size.z, GameObject.FindWithTag("projectile").transform.position.z));
     x = Mathf.Clamp(x, cratertex.width/2, xRes-cratertex.width/2);
     z = Mathf.Clamp(z, cratertex.height/2, yRes-cratertex.height/2);
     var areaT = tData.GetHeights(x-cratertex.width/2, z-cratertex.height/2, cratertex.width, cratertex.height);
         for (i = 0; i < cratertex.height; i++) {
         for (j = 0; j < cratertex.width; j++) {
             areaT [i,j] = areaT [i,j] - craterData[i*cratertex.width+j].a*0.01;
         }
         }        
     tData.SetHeights(x-cratertex.width/2, z-cratertex.height/2, areaT);    
     }
 }
 
 

I appreciate your help, in any coding language except Boo. -Hyperion

Comment
Add comment · Show 25
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 meat5000 ♦ · Aug 25, 2013 at 12:08 AM 0
Share

Is the new terrain as low as it can get? Click it and see if you can manually lower it.

avatar image Hyperion · Aug 25, 2013 at 12:15 AM 0
Share

I can move it, I can do whatever with it, except I cannot change its size.

avatar image Hyperion · Aug 25, 2013 at 12:16 AM 0
Share

And the size is too small for my liking, so that's why I want to apply it on a separate terrain that is much larger.

avatar image meat5000 ♦ · Aug 25, 2013 at 12:22 AM 0
Share

Are you saying it works on any terrain provided the size is the same?

avatar image Hyperion · Aug 25, 2013 at 12:26 AM 0
Share

Nope. It ONLY works on itself.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by meat5000 · Aug 31, 2013 at 02:08 AM

Erm DUDE. You are going to hate this :P

I deleted the terrain in the project and stuck my own in to it. I put the same scripts on it as the example and put the same figures in and...well it just worked. The only thing that was different was the actual crater texture which just came out black, but the deforming worked and everything. But just as I said in my first comment.... the original terrain had lots of height. A generated terrain has very little height.

I changed:

Terrain Height, Terrain Width, Terrain Height, Heightmap resolution, Detail resolution,

And it still worked.

EDIT: I changed everything in the terrain. It all just worked.

So, my answer, Make sure your scripts are in the right order and the numbers are the same (128,128,2). Also make sure Splat Alpha 0 is in the correct place! Literally copy the example! But most importantly make sure your terrain is not at the lowest height!

Comment
Add comment · Show 5 · 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 Hyperion · Aug 31, 2013 at 04:16 AM 0
Share

Wow, thank you very much! I will try it tomorrow so I can accept it! Just wondering, your new terrain was much larger than the old one, right? What order are your scripts in? And where do I make sure splat alpha 0 is in the right place?

avatar image meat5000 ♦ · Aug 31, 2013 at 10:09 AM 0
Share

I even increased the terrain size to 4000x4000!

Under terrain collider comes Cratermaker, then TextureChanger. I had manually put figures in to TextureChanger but I didn't even notice that it fills them in when you Play.

Ok Under Assets There is a folder called 'Terrain $$anonymous$$orpher'. In this folder are 4 js scripts. Cratermaker, Cursor, $$anonymous$$ouse, Texturechanger.

Under Assets, not in a folder, TerrainChanger.js and tData. tData has SplatAlpha 0 in it.

There is a folder called Detonator, but I don't think I've used anything in it.

avatar image Hyperion · Aug 31, 2013 at 07:49 PM 0
Share

O$$anonymous$$AY, thank you so much! Just as you said, I had to go into the terrain editor thing and manually raise the height. Before, I thought I had to change the position. What's strange is that the holes made are HUGE, unlike the original deformations.

avatar image meat5000 ♦ · Sep 01, 2013 at 07:48 AM 0
Share

The must have been scaled as a factor of the terrain size :)

Is the new terrain as low as it can get? Click it and see if you can manually lower it.

Lol, my first comment ;P

avatar image Hyperion · Sep 01, 2013 at 03:06 PM 0
Share

Lol, if only you had said raise it ins$$anonymous$$d. Thanks for your input!

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.

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Setting Scroll View Width GUILayout 1 Answer

Camera not through terrain 3 Answers

Collision with Terrain 2 Answers

How do i test whether my box collider is touching the floor or not? 2 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