0

有没有办法将 Perlin Noise 合并到 Python 中的 Ursina 游戏引擎中,让它有 Minecraft 的感觉?我想我可能正在做某事,但由于某种原因,y价值没有变化。你介意帮帮我吗?

我到目前为止的代码:

from ursina import *
from ursina.prefabs.first_person_controller import FirstPersonController
from perlin_noise import PerlinNoise;

app = Ursina()

noise = PerlinNoise(octaves=10, seed=1)

# Define a Voxel class.
# By setting the parent to scene and the model to 'cube' it becomes a 3d button.

class Voxel(Button):
    def __init__(self, position=(0,0,0)):
        super().__init__(
            parent = scene,
            position = position,
            model = 'cube',
            origin_y = .5,
            texture = 'white_cube',
            color = color.color(0, 0, random.uniform(.9, 1.0)),
            highlight_color = color.lime,
        )


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

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


for z in range(8):
    for x in range(8):
        y = .25 + noise([x, z])
        voxel = Voxel(position=(x, y,z))


player = FirstPersonController()
app.run()
4

2 回答 2

0

你可以使用这个:

seed=random.randint(1,1000000)
noise = PerlinNoise(octaves=3,seed=seed)
for z in range(8):
    for x in range(8):
        y = noise([x * 0.02,z * 0.02])
        y = math.floor(y * 7.5)
        voxel = Voxel(position=(x,y,z))
于 2022-01-26T14:16:49.483 回答
0

使用示例中所示,您必须使用额外的除法来缩放噪声值:

for z in range(8):
    for x in range(8):
        y = .25 + noise([x/8, z/8])
        voxel = Voxel(position=(x, y,z))

你可能想用一个常数替换那个幻数。

于 2021-06-27T06:47:13.937 回答