Ursina中的第一人称控制器y-pos逻辑



我有一个《我的世界》的克隆,我想看看玩家是否从岛上掉下来,它会退出游戏。我想如果我写的话。

if player.position == Vec3(x, -80, z):
quit()

它会退出游戏但那没用,所以我不知道该怎么办。

这是《我的世界》的克隆代码。

from ursina import *
from ursina.prefabs.first_person_controller import FirstPersonController
app = Ursina()
grass_color = color.rgb(1, 235, 113)
stone_color = color.rgb(138,141,143)
dirt_color = color.rgb(200, 157, 124)
block_pick = 1
def update():
if held_keys['escape']:
quit()
global block_pick
if held_keys['1']: block_pick = 1
if held_keys['2']: block_pick = 2
if held_keys['3']: block_pick = 3
class Voxel(Button):
def __init__(self, position = (0,0,0), color = color.white):
super().__init__(
parent = scene,
position = position,
model = 'cube',
origin_y = 0.5,
texture = 'white_cube',
color = color,
highlight_color = color,
)
def input(self,key):
if self.hovered:
if key == 'right mouse down':
if block_pick == 1:voxel = Voxel(position = self.position + mouse.normal, color = grass_color)
if block_pick == 2:voxel = Voxel(position = self.position + mouse.normal, color = stone_color)
if block_pick == 3:voxel = Voxel(position = self.position + mouse.normal, color = dirt_color)
if key == 'left mouse down':
destroy(self)

for z in range(20):
for x in range(20):
voxel = Voxel(position=(x,0,z), color = grass_color)
for y in range(3):
for x in range(20):
for z in range(20):
voxel = Voxel(position=(x,y + -3,z), color = dirt_color)
player = FirstPersonController()
app.run()

你只检查了玩家y位置的一个值,这是不起作用的——毕竟,你会很快摔倒。你可以检查球员的身高是否低于某个临界值:

def update():
if player.y < -80:
print('You fell to death!')
app.quit()

允许"无无限下落";,(这个问题没有被问,仍然在回答(

player = FirstPersonController(gravity=1)
def update():
print('Player is at Height = ', player.y)
if player.y < -10:
player.y = 100   # No infinite falling.

最新更新