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 aclee · Sep 30, 2014 at 07:15 PM · javascriptterrain

Cube terrain with perlin noise

hi, iv made a script (JS) that generate a 20x20 terrain of cubes, with random hills using perlin noise. alt text

but i have a few problems to solve and questions to ask:

when i generate the terrain again it gives me the exact same terrain, how would i make it automatically give me something else?

how would i make this infinite? how would i make it so when the player goes forward into the world the world would keep up with him? but still look normal (can i make something with chunks?)

how can i implement a seed system ware when you enter a seed you will get the same terrain every time?

sorry if it's a lot of questions...

the script: var size:Vector2 = new Vector2(20, 20); var height:float = 10.0f; var noiseStrength:float = 10.0f;

 private var perlinNoise;
 
 private var root:GameObject;
 
 function OnGUI(){
     if(GUI.Button (Rect(10, 10, 100, 30), "Generate")){
     Generate();
     }
 }
 
 function PerlinNoise(x:float, y:float){
     var noise:float = Mathf.PerlinNoise(x / noiseStrength, y/ noiseStrength);
     return noise * height;
 }
 
 function Generate(){
     Destroy(GameObject.Find("Terrain"));
     
     root = new GameObject("Terrain");
     root.transform.position = new Vector3(size.x/2, 0, size.y/2);
     
     for(var i:int = 0; i <= size.x; i++){
         for(var p:int = 0; p <= size.y; p++){
             var box:GameObject = GameObject.CreatePrimitive(PrimitiveType.Cube);
             box.transform.position = new Vector3( i, PerlinNoise( i, p ), p);
             box.transform.parent = root.transform;
         }
     }
     
     root.transform.position = Vector3.zero;
     print(PerlinNoise);
 }
capture.png (31.1 kB)
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 ExtremePowers · Sep 30, 2014 at 07:20 PM

For the result being the same all the time, add a seed to the x and y Like this: var noise:float = Mathf.PerlinNoise((Seed + x) / noiseStrength, (Seed + y) / noiseStrength);

To save the seed try

 var Seed = 0;
 
 function Start() {
     if (PlayerPrefs.HasKey("Seed")) {
         Seed = PlayerPrefs.GetInt("Seed");
     }
 }
 
 function OnGUI() {
     Seed = GUI.TextField(Rect(0, 50, 100,30), Seed.ToString()); 
     if (GUI.Button(Rect(0,0,100,30), "Save seed") {
         PlayerPrefs.SetInt("Seed", Seed);
         PlayerPrefs.Save();
     }
 }
 
 
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

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

27 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

procedural terrain 1 Answer

how do i make terrain in the new update unity 4.2.1 and i can't make terrain 1 Answer

Climb animation is glitchy and isnt working properly 0 Answers

editor script makes editor crash 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