Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by mefsh · May 26, 2017 at 06:06 PM · perlin noise

Perlin noise chunks not lining up. C#

Before anybody says to look it up I have been for 2 weeks. Have found nothing. And yes I know the code is sloppy I am very new to this.

So my problem is that the chucks are just not seamless. They have the correct x and z offset so I am lost on whats causing it. alt text I think the picture makes the problem pretty obvious.

Here is the code that is responsible for making the chunks.

Any Ideas? Am I doing this completely wrong? public class ChunkScript : MonoBehaviour {

 float waterHigh;
 float perlinScale;
 float highScale;
 Mesh mesh;
 public float seedX;
 public float seedY;
 int chunkSize;
 Vector3[] vertices;
 int[] trianagles;
 public GameObject waterObject;

 void Update()
 {
     //Generate new terrian
     if (Input.GetKeyDown(KeyCode.L))
     {
         Start();
     }
 }
 void Awake()
 {
     mesh = GetComponent<MeshFilter>().mesh;
 }

 void Start()
 {
     gameObject.name = "Chunk: " + transform.position.x + "," + transform.position.z;
     perlinScale = transform.parent.GetComponent<ChunkMasterScript>().perlinScale;
     highScale = transform.parent.GetComponent<ChunkMasterScript>().highScale;
     waterHigh = transform.parent.GetComponent<ChunkMasterScript>().waterHigh;
     chunkSize = transform.parent.GetComponent<ChunkMasterScript>().chunkSize;

     waterObject.transform.position = new Vector3(waterObject.transform.position.x, waterHigh, waterObject.transform.position.z);
     waterObject.transform.localScale = new Vector3(chunkSize / 10, 1, chunkSize / 10);


     seedX = transform.parent.GetComponent<ChunkMasterScript>().seedX;
     seedY = transform.parent.GetComponent<ChunkMasterScript>().seedY;

     BuildChunkMesh();
     UpdateChunkMesh();
 }
 
 void BuildChunkMesh()
 {
     float perlinBlockHigh;
     int v = 0;
     int t = 0;
     vertices = new Vector3[chunkSize * chunkSize * 8];
     trianagles = new int[chunkSize * chunkSize * 36];

     for (int x = 0; x < chunkSize; x++)
     {
         for (int y = 0; y < chunkSize; y++)
         {
             float xCoord = seedX + transform.position.x + x / perlinScale;
             float yCoord = seedY + transform.position.z + y / perlinScale;
             perlinBlockHigh = Mathf.PerlinNoise(xCoord, yCoord) * highScale;

             vertices[v+0] = new Vector3(x - chunkSize / 2, 0, y - chunkSize / 2);
             vertices[v+1] = new Vector3(x+1 - chunkSize / 2, 0, y - chunkSize / 2);
             vertices[v+2] = new Vector3(x - chunkSize / 2, 0, y+1 - chunkSize / 2);
             vertices[v+3] = new Vector3(x+1 - chunkSize / 2, 0, y+1 - chunkSize / 2);

             vertices[v + 4] = new Vector3(x - chunkSize / 2, perlinBlockHigh, y - chunkSize / 2);
             vertices[v + 5] = new Vector3(x + 1 - chunkSize / 2, perlinBlockHigh, y - chunkSize / 2);
             vertices[v + 6] = new Vector3(x - chunkSize / 2, perlinBlockHigh, y + 1 - chunkSize / 2);
             vertices[v + 7] = new Vector3(x + 1 - chunkSize / 2, perlinBlockHigh, y + 1 - chunkSize / 2);


             //bottem
             trianagles[t] = v + 1;
             trianagles[t + 1] = v + 2;
             trianagles[t + 2] = v;
             trianagles[t + 3] = v + 3;
             trianagles[t + 4] = v + 2;
             trianagles[t + 5] = v + 1;
             //top
             trianagles[t + 6] = v + 4;
             trianagles[t + 7] = v + 6;
             trianagles[t + 8] = v + 5;
             trianagles[t + 9] = v + 5;
             trianagles[t + 10] = v + 6;
             trianagles[t + 11] = v + 7;
             //front
             trianagles[t + 12] = v;
             trianagles[t + 13] = v + 4;
             trianagles[t + 14] = v + 1;
             trianagles[t + 15] = v + 1;
             trianagles[t + 16] = v + 4;
             trianagles[t + 17] = v + 5;
             //back
             trianagles[t + 18] = v + 3;
             trianagles[t + 19] = v + 7;
             trianagles[t + 20] = v + 2;
             trianagles[t + 21] = v + 2;
             trianagles[t + 22] = v + 7;
             trianagles[t + 23] = v + 6;
             //right
             trianagles[t + 24] = v + 1;
             trianagles[t + 25] = v + 5;
             trianagles[t + 26] = v + 3;
             trianagles[t + 27] = v + 3;
             trianagles[t + 28] = v + 5;
             trianagles[t + 29] = v + 7;
             //left
             trianagles[t + 30] = v + 2;
             trianagles[t + 31] = v + 6;
             trianagles[t + 32] = v + 4;
             trianagles[t + 33] = v;
             trianagles[t + 34] = v + 2;
             trianagles[t + 35] = v + 4;
             v += 8;
             t += 36;


         }
     }
 }

 void UpdateChunkMesh()
 {
     mesh.Clear();
     mesh.vertices = vertices;
     mesh.triangles = trianagles;
     mesh.RecalculateNormals();
     GetComponent<MeshCollider>().sharedMesh = mesh;
 }

 void PlayerEntered()
 {
     GetComponentInParent<ChunkMasterScript>().LoadChunksAroundPlayer(gameObject);

 }

}

screenshot-2017-05-25-173434.png (485.3 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

0 Replies

· Add your reply
  • Sort: 

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

103 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 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 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 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

Yet another "Mathf.PerlinNoise() returning the same value" problem 0 Answers

Perlinnoise, blocks load far apart 0 Answers

Creating ridged perlin noise 0 Answers

Mesh collider only working on part of procedurally generated mesh 1 Answer

Endless Road Random Generate -Ball Racing, Using Perlin Noise 0 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