[Python] How do i make a meshcollider for a full model?

Discussão em 'Python' iniciado por Stack, Maio 8, 2025.

  1. Stack

    Stack Membro Participativo

    I was making a game with ursina, and wanted to add a collider to my imported 3d model, more specifically a meshcollider. The meshcollider I coded only made one part of the 3D model a collider. my model looks like this only one oval/sphere has a collider, not every. my code:

    from ursina import *

    app = Ursina()

    window.fullscreen = True

    mouse.locked = True
    mouse.visible = False

    world = Entity(model='world10.fbx', texture='world.png', collider='mesh')

    player = Entity(model='sphere', color=color.orange, scale_y=2, collider='sphere', position=(0,5,0))
    camera.parent = player
    camera.position = (0, 1.5, 0)
    camera.rotation = (0, 0, 0)
    camera.fov = 90

    Sky()
    DirectionalLight().look_at(Vec3(1, -1, -1))

    speed = 5
    sprint_speed = 10
    crawl_speed = 2
    jump_force = 5
    velocity_y = 0
    gravity = 9.81
    grounded = False

    def update():
    global velocity_y, grounded

    player.rotation_y += mouse.velocity[0] * 100
    camera.rotation_x -= mouse.velocity[1] * 100
    camera.rotation_x = clamp(camera.rotation_x, -90, 90)

    direction = Vec3(0, 0, 0)

    if held_keys['w']:
    direction += player.forward
    if held_keys['s']:
    direction -= player.forward
    if held_keys['a']:
    direction -= player.right
    if held_keys['d']:
    direction += player.right

    direction = direction.normalized()

    current_speed = speed
    if held_keys['shift']:
    current_speed = sprint_speed
    elif held_keys['alt']:
    current_speed = crawl_speed
    player.scale_y = 1
    else:
    player.scale_y = 2

    ray = raycast(player.world_position + Vec3(0,0.1,0), Vec3(0,-1,0), distance=1.1, ignore=(player,))
    grounded = ray.hit

    if grounded:
    velocity_y = 0
    if held_keys['space']:
    velocity_y = jump_force
    else:
    velocity_y -= gravity * time.dt

    player.position += direction * current_speed * time.dt
    player.y += velocity_y * time.dt

    def input(key):
    if key == 'c':
    world.collider = None

    app.run()



    I tried to take the model apart and import every model one by one but of curse, it isnt a good way to do it especially if you have more than 500 houndred meshes.

    Continue reading...

Compartilhe esta Página