1

我在运行我的代码时遇到了一些问题。

我希望我的立方体同时跳跃和移动。

当我按下up arrowleft arrow按下space时,绑定的跳跃功能space不起作用

但它在同时按下其他键(如left arrow和)时效果很好down arrow

当我更改arrowswasd.

是 ursina 的错误还是我犯了一些错误?

我的代码:

import ursina as us

app = us.Ursina()

class Player(us.Entity):
    def __init__(self):
        super().__init__(
            parent=us.scene,
            model='cube',
            position=(0, -1, 5),
            rotation=(0, 45, 0),
            texture='white_cube',
            color=us.color.azure,
            )
        us.camera.position = (0, 0, 0)
        us.camera.rotation = (0, -1, 0)
        
        self.gravity = 0.01
        self.strength = 0.2
        self.v = None
        
    def update(self):
        if us.held_keys['up arrow']:
            self.position += self.forward * us.time.dt
        if us.held_keys['down arrow']:
            self.position += self.back * us.time.dt
        if us.held_keys['right arrow']:
            self.position += self.right * us.time.dt
        if us.held_keys['left arrow']:
            self.position += self.left * us.time.dt
        
        if us.held_keys['space']:
            self.jump()
        
        if self.v != None:
            self.v -= self.gravity
            if self.v > -self.strength:
                self.position += (0, self.v, 0)
            else:
                self.v = None
        
        
    def jump(self):
        if self.v == None:
            self.v = self.strength
        

player = Player()
us.Sky()

app.run()
4

0 回答 0