pythongame-physicsursina3d-engine

I can't get the Bullet-for-ursina mechanic colliders to work correctly for ursina


I have been using ursina for a little bit now, and this isn't the first problem I have encountered. Needless to say, yet again I have another. I am trying to get physics to work in ursina so cubes or other entities can have mass and fall. I have heard that Bullet-for-ursina is a good idea as listed in here https://github.com/LooksForFuture/Bullet-for-ursina. Though, ursina and this GitHub have very little documentation, especially the GitHub. Anyways, I have tried using the built in ursina colliders as well as the ones for the BulletWorld to no avail. My problem that is occurring is that when I add the Mesh collider to my enemy, 1 of a couple things will happen.

  1. My enemy Entity will fall through the world.
  2. My enemy Entity will somewhat work but I can't move it and it it buggy.
  3. This problem occurs every time no matter how I tweak the code. My models' collider for physics3d always seem to be placed way above my entitles, and the scale for the box collider is much larger than it should be.

This is my current code:

from ursina import *
from physics3d import *
from panda3d.bullet import BulletWorld
from ursina.prefabs.first_person_controller import FirstPersonController
enemy = Entity(position=(10,-8,-15),scale=(1,1,1),model="cube")
app=Ursina()
ground = Entity(
    model="cube",
    scale=(200,5,200),
    texture="grass",
    position=(0,-22,0),
    name="floor",
    collider="box"
)

character = Entity(model="cube",rotation_y = 90,name="player")

player = FirstPersonController(model=character,origin=(0,-0.5,0))

world = BulletWorld()
Debugger(world, wireframe=True)
world.setGravity(Vec3(0, -9.81, 0))

MeshCollider(world,enemy,mass=1)
BoxCollider(world,ground)

def update():
    dt = time.dt
    world.doPhysics(dt)

app.run()

I have exempted some code deemed unnecessary to this project; otherwise, it would be really long. If you would like it, of course you can just ask. Also, a few things to note: I have personally added the FirstPersonController module to my code so I could tweak it. So if it seems like I am defining a class object with no previous class, I have just not shown it in this code snippet because it is unnecessary.

In this example, if tested, you can see that the cube does hit the collider, but it is much farther up from the actual ground.


Solution

  • The problem was caused by a little bug. I've fixed it and have update the repo. So, please use the new version.
    Good luck.