Python 如何将碰撞检测添加到ursina中的二维对象?

Python 如何将碰撞检测添加到ursina中的二维对象?,python,entity,collision-detection,Python,Entity,Collision Detection,嗨,我想知道如何将碰撞检测添加到ursina中的2d实体中。我是初学者,所以这对我来说很难。这是我的代码附件: from ursina import * def update(): if held_keys['a']: player1.x -= 1 * time.dt if held_keys['d']: player1.x += 1 * time.dt if held_keys['w']: pla

嗨,我想知道如何将碰撞检测添加到ursina中的2d实体中。我是初学者,所以这对我来说很难。这是我的代码附件:

from ursina import *

def update():
    if held_keys['a']:    
        player1.x -= 1 * time.dt
    if held_keys['d']:    
        player1.x += 1 * time.dt
    if held_keys['w']:    
        player1.y += 1 * time.dt
    if held_keys['s']:    
        player1.y -= 1 * time.dt
        
    if held_keys['j']:    
        player2.x -= 1 * time.dt
    if held_keys['l']:    
        player2.x += 1 * time.dt
    if held_keys['i']:    
        player2.y += 1 * time.dt
    if held_keys['k']:    
        player2.y -= 1 * time.dt



root = Ursina()

player_texture1 = load_texture('assets/player1.png')
player_texture2 = load_texture('assets/player2.png')

player1 = Entity(model = 'quad', scale = (1,1), texture = player_texture1)
player2 = Entity(model = 'quad', scale = (1,1), texture = player_texture2)



root.run()
将此添加到代码中:“collider='box'”,例如,我有一个代码:

class Floor(Entity):
    def __init__(self, position=(0, -103, 0)):
        super().__init__(
            parent=scene,
            position=position,
            model='cube',
            texture = 'white_cube',
            color = color.rgb(34,139,34),
            scale = 200,
            double_sided=True)
要将碰撞添加到实体,只需将其作为任何其他参数添加即可:

class Floor(Entity):
    def __init__(self, position=(0, -103, 0)):
        super().__init__(
            parent=scene,
            position=position,
            model='cube',
   ------>  collider='box',  <--------
            texture = 'white_cube',
            color = color.rgb(34,139,34),
            scale = 200,
            double_sided=True)
班级楼层(实体):
定义初始化(self,position=(0,-103,0)):
超级()。\uuu初始化__(
父=场景,
位置=位置,
model='cube',
------>对撞机,