在Ursina引擎中如何锁定相机?

4
我正在使用Ursina引擎创建一个2D马里奥风格的平台游戏,我想在玩家向左移动时锁定相机,并停止相机跟踪玩家。我查看了文档,但似乎很贫乏。有人已经使用过这个游戏引擎吗?
3个回答

10

您可以像设置其他实体一样设置相机的位置和旋转。以下代码将限制x为0:

camera.x = max(camera.x, 0)

或者,如果您已经让相机成为其他对象的子对象,则可能希望设置世界位置:

camera.world_x = max(camera.world_x, 0)

你是在GitHub上制作Ursina的pokepetter吗?如果是,由于我没有GitHub帐户来报告它,我遇到了一个似乎没有解决方案的错误。这正常吗? https://stackoverflow.com/questions/66873751/why-cant-i-load-a-obj-file-into-python-ursina/66942136#66942136 如果您是制造者,请提供任何您可以提供的帮助,非常感谢您对Ursina的了解。 - SamTheProgrammer
@Password-Classified,看起来唯一的问题是规模,那你说的 bug 是什么?规模小是因为模型小。 - DiamondsBattle
在创建了一个账户并提交问题后,我得知需要对模型进行三角剖分。@DiamondsBattle - SamTheProgrammer

0

只需添加 camera.position 和 camera.rotation:

camera.position=(1, 10, -10)
camera.rotation=(1, 10, -10)

0
你可以使用一个 if 语句来澄清你想要的,并使用一个 previous_x 变量。
    prev_x = camera.x

    def update(): #the following code should be added to your update function which is already called...

        if prev_x < camera.x:
        
            lock() 
#this should be a function which is linked
#to your code which moves the camera. 
#A way to do this would be to set a 
#certain variable to true and use the following code:

locked = False
if not locked:
    function_which_moves_camera_left()
    
#The lock() function would be:

def lock():
    locked = True
    
#You could unlock it with the function:

def unlock():
    locked = False

所以... 通过使用if语句,你可以创建一个使用变量作为标志的函数。检查此变量允许你锁定相机。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接