好的,在我的代码中,我试图让相机跟随我的播放器,我正在遵循我发现的关于堆栈溢出的教程。但当我这么做的时候;跌倒";它在y轴上旋转,这是怎么发生的,我也试图产生地面类,但我认为我没有。看了所有关于熊的文档,看了如何制作视频,我仍然不明白为什么。我做错了什么?
from ursina import *
from ursina.prefabs.first_person_controller import FirstPersonController
app = Ursina()
EditorCamera()
cam = FirstPersonController()
class Player(Entity):
def __init__(self, **kwargs):
super().__init__(model='cube', color=color.orange, collider='box', origin = (0, 0, -2), parent = cam)
self.health_bar = Entity(parent=self, model='quad', color=color.red, scale_y=.1, y=1.2)
self.max_health = 100
self.health = self.max_health
class Beings(Entity):
def __init__(self, **kwargs):
super().__init__(model='cube', color=color.gray, scale=2, collider='box', position=Vec3(1,0,2), origin_y=-.5)
self.health_bar = Entity(parent=self, model='quad', color=color.red, scale_y=.1, y=1.2)
self.max_health = 100
self.health = self.max_health
class Ground(Entity):
def __init__(self, **kwargs):
super().__init__(model='plane', color=color.gray, scale=2, collider='mesh', position=Vec3(1,0,2), origin_y=-.4)
self.health_bar = Entity(parent=self, model='quad', color=color.red, scale_y=.1, y=1.2)
self.max_health = 100
self.health = self.max_health
class Buildings(Entity):
def __init__(self, **kwargs):
super().__init__(model='cube', color=color.gray, scale=2, collider='box', position=Vec3(1,0,2), origin_y=-.5)
self.health_bar = Entity(parent=self, model='quad', color=color.red, scale_y=.1, y=1.2)
self.max_health = 100
self.health = self.max_health
class plants(Entity):
def __init__(self, **kwargs):
super().__init__(model='cube', color=color.gray, scale=2, collider='box', position=Vec3(1,0,2), origin_y=-.5)
self.health_bar = Entity(parent=self, model='quad', color=color.red, scale_y=.1, y=1.2)
self.max_health = 100
self.health = self.max_health
class Earth(Entity):
def __init__(self, **kwargs):
super().__init__(model='cube', color=color.gray, scale=2, collider='box', position=Vec3(1,0,2), origin_y=-.5)
self.health_bar = Entity(parent=self, model='quad', color=color.red, scale_y=.1, y=1.2)
self.max_health = 100
self.health = self.max_health
b = Beings()
p = Player()
def update():
Ground()
p.z += (held_keys['w'] - held_keys['s']) * time.dt * 6
p.x += (held_keys['d'] - held_keys['a']) * time.dt * 6
if p.intersects(b).hit:
b.color = color.lime
print('player is inside trigger box')
else:
b.color = color.gray
app.run()
因为地面在玩家底部上方,所以它正在下落。这可以通过向下移动地面来解决,例如y=-1。此外,将origin_y设置为负值,就像您所做的那样,将向上移动模型和碰撞器。
我认为这将对您有所帮助。你必须更改地面和玩家的y
坐标:
from ursina import *
from ursina.prefabs.first_person_controller import FirstPersonController
app = Ursina()
# EditorCamera()
# cam = FirstPersonController(y=5)
class Player(FirstPersonController):
def __init__(self, **kwargs):
super().__init__(model='cube', color=color.orange, collider='box')
self.y=5
self.health_bar = Entity(parent=self, model='quad', color=color.red, scale_y=.1, y=1.2)
self.max_health = 100
self.health = self.max_health
self.origin = (0, 0, -1)
# camera.position=(0, 1, -3)
class Beings(Entity):
def __init__(self, **kwargs):
super().__init__(model='cube', color=color.gray, scale=2, collider='box', position=Vec3(1,0,2), origin_y=-.5)
self.health_bar = Entity(parent=self, model='quad', color=color.red, scale_y=.1, y=1.2)
self.max_health = 100
self.health = self.max_health
class Ground(Entity):
def __init__(self, **kwargs):
super().__init__(model='plane', texture_scale=(50, 50), texture='white_cube', scale=50, collider='mesh', position=Vec3(1,0,2))
self.health_bar = Entity(parent=self, model='quad', color=color.red, scale_y=.1, y=1.2)
self.max_health = 100
self.health = self.max_health
self.y = -1 #change this as per your requirment
self.texture='white_cube'
class Buildings(Entity):
def __init__(self, **kwargs):
super().__init__(model='cube', color=color.gray, scale=2, collider='box', position=Vec3(1,0,2), origin_y=-.5)
self.health_bar = Entity(parent=self, model='quad', color=color.red, scale_y=.1, y=1.2)
self.max_health = 100
self.health = self.max_health
class plants(Entity):
def __init__(self, **kwargs):
super().__init__(model='cube', color=color.gray, scale=2, collider='box', position=Vec3(1,0,2), origin_y=-.5)
self.health_bar = Entity(parent=self, model='quad', color=color.red, scale_y=.1, y=1.2)
self.max_health = 100
self.health = self.max_health
class Earth(Entity):
def __init__(self, **kwargs):
super().__init__(model='cube', color=color.gray, scale=2, collider='box', position=Vec3(1,0,2), origin_y=-.5)
self.health_bar = Entity(parent=self, model='quad', color=color.red, scale_y=.1, y=1.2)
self.max_health = 100
self.health = self.max_health
b = Beings()
p = Player()
g = Ground()
def update():
if p.intersects(b).hit:
b.color = color.lime
print('player is inside trigger box')
else:
b.color = color.gray
app.run()