0

Is there a way to incorporate Perlin Noise into my Minecraft Clone? I have tried many different things that did not work.

Here is a snippet of my code:

from ursina import *
from ursina.prefabs.first_person_controller import FirstPersonController
from ursina.shaders import camera_grayscale_shader
app = Ursina()

grass = 'textures/grass.jpg'

class Voxel(Button):
    def __init__(self, position = (0,0,0), texture = grass):
        super().__init__(
            model='cube',
            texture=texture,
            color=color.color(0,0,random.uniform(.823,.984)),
            parent=scene,
            position=position,
        )

    def input(self, key):
        if self.hovered:
            if key == 'right mouse down':
                voxel = Voxel(position = self.position + mouse.normal, texture = plank)
                

            if key == 'left mouse down':
                destroy(self)

for z in range(16):
    for x in range(16):
            voxel = Voxel(position = (x,0,z))

I need to create an algorithm that randomly generates SMOOTH terrain like hills and plains, there are no tutorials on how to do it. Please help

Akshay Sehgal
  • 18,741
  • 3
  • 21
  • 51
  • Hi I have answered a similar question here check it out: www.stackoverflow.com/questions/65888586/ursina-perlin-noise – Dev123 Feb 08 '21 at 04:50
  • Does this answer your question? [Ursina - Perlin Noise](https://stackoverflow.com/questions/65888586/ursina-perlin-noise) – Infinity 857 Oct 29 '21 at 01:28

1 Answers1

1

Yes, there's a way to incorporate perlin noise into a minecraft clone, here's a simple example of random terrain in a minecraft clone.

from perlin_noise import PerlinNoise
import random

noise = PerlinNoise (octaves=3,seed=random.randint(1,1000000))

for z in range(-10,10):
    for x in range(-10,10):
        y = noise([x * .02,z * .02])
        y = math.floor(y * 7.5)
        voxel = Voxel(position=(x,y,z))

And this is the final result: https://i.stack.imgur.com/ezx7m.jpg

Remember you need to install perlin noise, to do this just write this in the terminal: pip install perlin-noise