简体   繁体   中英

Ursina: How can I add a mesh collider for a blender object?

I'm trying to make a Game with Ursina and Python. For that, I want to create a little Terrain in Blender. The mesh is showing up correctly if I disable collision but if I try to enable it, the game gives me an Error, that the mesh has no "mesh_collider". And I have no Idea how to add one.

The Error:

Traceback (most recent call last):
  File "c:\Users\email\Desktop\Iwas3dSchosch\main.py", line 8, in <module>
    level.mesh_collider.collider = 'mesh'
AttributeError: 'Entity' object has no attribute 'mesh_collider'

The Code for the Object:

level = load_blender_scene('map_data')
t = time.time()
level.mesh_collider.collider = 'mesh'
level.mesh_collider.visible = True

There are 2 problems here, First is Inheritance, the Mesh importer shell has no Attributes, it's all functions. what you want to do is create an Entity() instance call and pass in the Mesh and collider arguments into it. The 2nd problem is you're using Load_blender_scene() when load_model() is what you want.

level = load_model('map_data')
# t = time.time()
Entity(model=level, collider=level, collision=True)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM