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
2
Question by JiffyJuff · Jul 04, 2013 at 02:42 AM · terrainrandomperlin noise

How does Mathf.PerlinNoise Work?

I've been trying to make a sort of randomized terrain for a while, and I'm unable to write a perlin noise function myself, partly due to laziness and partly to being a total noob.

So I borrowed the Mathf.PerlinNoise function. The documentation says that you give it the two coordinates, and it gives you a random number on a texture with the same coordinates or something.

But when I printed a bunch of Mathf.PerlinNoises, with different hand-typed values, all of them printed the same number : 0.4652731. So can anyone explain this to me?

EDIT: Here's my script:

 function Start () {
     print(Mathf.PerlinNoise(0, 0));
     print(Mathf.PerlinNoise(2, 0));
     print(Mathf.PerlinNoise(0, 5));
     print(Mathf.PerlinNoise(10, 3));
     print(Mathf.PerlinNoise(2, 0));
     print(Mathf.PerlinNoise(1, 1));
 }


Here's the results (one of them):

0.4652731 UnityEngine.MonoBehaviour:print(Object) PerlinHeight:Start() (at Assets/PerlinHeight.js:5)

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

4 Replies

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

Answer by Eric5h5 · Jul 04, 2013 at 04:52 AM

Whole numbers will return the same result; use fractions.

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 JiffyJuff · Jul 04, 2013 at 06:32 AM 0
Share

Ohhhh... Thanks! I'll experiment a bit with it.

avatar image
1

Answer by robertbu · Jul 04, 2013 at 03:41 AM

Think of PerlinNoise() as producing value in a random terrain. That is adjacent values are not random, but instead will produce similar values (perhaps a bit more, or perhaps a bit less) as if you are walking some hilly countryside. I find that when working with Perlin noise I have to get the range of values right. Here is a answer with a script for creating a hilly plane. It should be straight forward to modify it for use in a Terrain.

http://answers.unity3d.com/questions/417793/perlin-noise-plane-manipulation.html

Comment
Add comment · 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 JiffyJuff · Jul 04, 2013 at 04:30 AM 0
Share

But I don't want a mesh - I want the heights of different points.

avatar image Eric5h5 · Jul 04, 2013 at 04:53 AM 0
Share

The mesh part is irrelevant; the point is that it's a demonstration of how perlin noise works.

avatar image robertbu · Jul 04, 2013 at 05:15 AM 0
Share

As @Erich5h5 says, the link was to demonstrate how to use PerlinNoise(). Lines 24-26 make the height calculation. The height of the mesh (which will be the same or similar calculation for a Terrain) is done on line 26. If you know Terrains, the conversion should be easy.

avatar image
1

Answer by gonzolot · Sep 25, 2016 at 11:14 AM

Mathf.PerlinNoise work with smaller values marked as float. Like:

 Debug.Log(Mathf.PerlinNoise(0 / 100f, 0 / 100f));
 Debug.Log(Mathf.PerlinNoise(2 / 100f, 0 / 100f));
 Debug.Log(Mathf.PerlinNoise(0 / 100f, 5 / 100f));
 Debug.Log(Mathf.PerlinNoise(10 / 100f, 3 / 100f));
 Debug.Log(Mathf.PerlinNoise(2 / 100f, 0 / 100f));
 Debug.Log(Mathf.PerlinNoise(1 / 100f, 1 / 100f));

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 ebogguess · Jul 04, 2013 at 03:42 AM

I've never used it, but from the documentation, it appears that given x and y coordinates, the algorithm will return a value between 0.0 and 1.0. Different coordinates should give different values.

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 JiffyJuff · Jul 04, 2013 at 04:31 AM 0
Share

That's what I thought too, but different coordinates somehow yield the same results.

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

Random Terrain Generation (Trees, Details, Textures) by passing a Seed? 0 Answers

Any Reason this would make Unity Freeze up? 0 Answers

Tree position on random Terrain (y axis) 0 Answers

Tiling problem with Perlin generated terrain chunks 1 Answer

How can I correctly offset seeded perlin noise over multiple terrains? 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