0

Is there a way to incorporate Perlin Noise into my Minecraft Clone? I have tried many different things that didn't 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 am trying to make randomly generated terrain using cubes and Perlin's Noise. There are no tutorials on how to use it.

2 Answers2

2

I am a 12-year-old game developer and I guess this could be a solution to your problem again this is not perfect I used the random module to make randomized x,y, and z values you can make adjustments to the values according to your preferences I am sorry if there is an indentation error in the code by the way this is the code:

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




class Voxel(Button):
    def __init__(self, position=(0, 0, 0)):
        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)

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




for z in range(random.randint(5,10)):
    print(z)
    for x in range(random.randint(5,7)):
        print(x)
        voxel = Voxel(position=(x, random.randint(0,2), z))


player  = FirstPersonController()
app.run()

this is a screenshot of the product:

https://i.stack.imgur.com/Ktr1Q.png

Dev123
  • 21
  • 4
1

Yes, there's a way to incorporate perlin noise into 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))

This is a simple example of how you can make random terrain in a minecraft clone, 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