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 thormond · Sep 01, 2013 at 04:01 PM · terrain data

Dynamic Terrain Painting

Hi, I need to be able to generate dynamic frozen ground on the terrain that slows everything passing through, for that I have to be able to temporarily set terrain's texture via script in certain radius from the target. Is this possible to implement on the standard existing Terrain game object?

Comment
Add comment
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
0
Best Answer

Answer by thormond · May 23, 2014 at 11:03 PM

correct answer was Projector (with some UnityPro or custom shader) combined with sphere collider https://docs.unity3d.com/Documentation/Components/class-Projector.html

Comment
Add comment · 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
0

Answer by Hyperion · Sep 01, 2013 at 04:19 PM

It's possible if you assign your terrain multiple textures. Say texture 0 is ground and texture 1 is frozen-ground. In script, you can access which one you're using.

Comment
Add comment · Show 2 · 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 thormond · Sep 01, 2013 at 05:43 PM 0
Share

Well I'm already using multiple terrain textures via editor UI, what i want to know is: how do I take texture 1 and tell unity with script to draw with this texture on the terrain in certain radius ? ( and then to undo this change after X seconds )

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

You should use the 'add new comment' button next time. Anyway, I'll just show you a script that changes texture upon mouse click using the second texture.

 //attach this to camera
 static var mousepos : Vector3;
 function Update () 
 {
     var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
     var hit : RaycastHit;
     if (Physics.Raycast (ray, hit,1000))
     {
         mousepos = hit.point;
     }
 }

Then:

 //attach this to terrain
 var saved : float[,,];
 private var tData : TerrainData;
 var cratertex : Texture2D;
 var craterData;
 var xRes: int;
 var yRes: int;
 var layers: int;
 
 function Start () {
 tData = Terrain.activeTerrain.terrainData;
 yRes = tData.alphamapHeight;
 xRes = tData.alphamapWidth;
 layers = tData.alphamapLayers;
 craterData = cratertex.GetPixels();
 saved = tData.GetAlphamaps (0, 0, xRes, yRes);
 }
 
 function OnApplicationQuit () {
 tData.SetAlphamaps (0,0,saved);
 }
 function Update () {
 if (Input.Get$$anonymous$$ouseButtonDown(0)){
 var g : int = $$anonymous$$athf.Lerp(0, xRes, $$anonymous$$athf.InverseLerp(0, tData.size.x, mouse.mousepos.x));
 var b : int = $$anonymous$$athf.Lerp(0, yRes, $$anonymous$$athf.InverseLerp(0, tData.size.z, mouse.mousepos.z));
 g = $$anonymous$$athf.Clamp(g, cratertex.width/2, xRes-cratertex.width/2);
 b = $$anonymous$$athf.Clamp(b, cratertex.height/2, yRes-cratertex.height/2);
 var area = tData.GetAlphamaps(g-cratertex.width/2, b-cratertex.height/2, cratertex.width, cratertex.height);
 for (x = 0; x < cratertex.height; x++) {
     for (y = 0; y < cratertex.width; y++) {
     for (z = 0; z < layers; z++){    
     if (z == 1){
     area [x,y,z] += craterData[x*cratertex.width + y].a;
     }
     else{    
     area [x,y,z] -= craterData[x*cratertex.width + y].a;    
     }    
         }}}
 tData.SetAlphamaps (g-cratertex.width/2,b-cratertex.height/2,area);
 }
 }
 

And the script will require a 'texture' so I'll attach it.alt text Important: $$anonymous$$ake sure the texture import settings are: alt text

Add the texture to the script.

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

19 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

How to import the object from server to unity 2 Answers

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

Material doesn't have a color property '_Color' 4 Answers

Setting Scroll View Width GUILayout 1 Answer


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