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 Major · Nov 08, 2013 at 11:13 PM · gameobjecttransformrandomrandom.rangegenerating

Generating a Displacement Map in Unity3d?

So far I have been able to spawn randomly sized spheres on the go. but I want these to look like asteroids, and not perfectly smooth spheres. I would like to distort the geometry of an object as it is generating in order to make it feel more like you are actually flying among asteroids.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by tanoshimi · Nov 08, 2013 at 11:48 PM

I suggest you look at the procedural examples project in the asset store - particularly the heightmap generator and crumple modifier to show how to deform a mesh in code at runtime.

alt text


sphere.jpg (56.1 kB)
Comment
Add comment · Show 1 · 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 Major · Nov 09, 2013 at 12:42 AM 0
Share

Here is my script:

var copper : boolean = false; var gold : boolean = false;

 //var astoids : GameObject[];
 var metal : int[];
 
 function Start () 
 {
     randnumb = Random.Range (1,100);
 for (i=0;i < randnumb; i += 1){
 
     var astroid : GameObject = GameObject.CreatePrimitive(PrimitiveType.Sphere);
     astroid.transform.position = Vector3(Random.Range(0, 10000), Random.Range(0, 10000), Random.Range(0, 10000));
 
     var randomx = Random.Range(50, 300.0);
     var randomy = Random.Range(50, 300.0);
     var randomz = Random.Range(50, 300.0);
     
     astroid.transform.localScale = Vector3(randomx, randomy, randomz);
     
     var volume = 4/3*$$anonymous$$athf.PI*randomx*randomy*randomz;    
     
     var metals = Random.Range(0, metal.length);
     
     if(metals == 0)
         copper = true;  
         
     if(metals == 1)
         gold = true;
         
     if(copper == true)
     {
         var copper1 = 8.96 * Random.Range(1, 100);
         astroid.tag = 'Copper';
     }
     
     if(gold == true)
     {
         var gold1 = 19.32 * Random.Range(1, 100);
         astroid.tag = 'Gold';
     }
     
     if(copper || gold == true)
     {
         var resources = copper1 || gold1; 
     }
     
     astroid.AddComponent(Rigidbody);
     astroid.rigidbody.mass = 2.9 * volume + resources;
     astroid.AddComponent("Gravity");
 }
 }


Here is the cumplemesh script:

 var scale = 1.0;
 var speed = 1.0;
 var recalculateNormals = false;
 
 private var baseVertices : Vector3[];
 private var noise : Perlin;
 
 function Start ()
 {
     noise = new Perlin ();
 }
 
 function Update () {
     var mesh : $$anonymous$$esh = GetComponent($$anonymous$$eshFilter).mesh;
     
     if (baseVertices == null)
         baseVertices = mesh.vertices;
         
     var vertices = new Vector3[baseVertices.Length];
     
     var timex = Time.time * speed + 0.1365143;
     var timey = Time.time * speed + 1.21688;
     var timez = Time.time * speed + 2.5564;
     for (var i=0;i<vertices.Length;i++)
     {
         var vertex = baseVertices[i];
                 
         vertex.x += noise.Noise(timex + vertex.x, timex + vertex.y, timex + vertex.z) * scale;
         vertex.y += noise.Noise(timey + vertex.x, timey + vertex.y, timey + vertex.z) * scale;
         vertex.z += noise.Noise(timez + vertex.x, timez + vertex.y, timez + vertex.z) * scale;
         
         vertices[i] = vertex;
     }
     
     mesh.vertices = vertices;
     
     if (recalculateNormals)    
         mesh.RecalculateNormals();
     mesh.RecalculateBounds();
 }


I am not 100% on how to combine these two scripts.

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

18 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

Related Questions

Teleport to a random height 1 Answer

Transform to a random height 0 Answers

Pick a Transform[] or GameObject[] from script? 2 Answers

Semi-random prefabs generating 0 Answers

Generating an object in a random y position? c# 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