Is there a way to find the coordinates of all vertices of an Ursina Entity?

74 views Asked by At

I have the following code to create a cube and a plane.

from ursina import *

bodies = set()
G = 0.002

app = Ursina(render_mode='colliders')

ground = Entity(model='plane', color=rgb(230,230,230), scale=10, collider='mesh')
ground.collider.visible = True

cube = Entity(model='cube', color=rgb(100, 100, 100), scale=2, position=Vec3(0, 5,0), collider='mesh', rotation=Vec3(45, 45, 45))
cube.collider.visible = True
bodies.add((cube, 0))

def update():
    global bodies
    new_bodies = set()
    for body, v in bodies:    
        hit_info = raycast(Vec3(cube.X, cube.Y, cube.Z) , Vec3(0, -1, 0), ignore=(body,), distance=body.scale.y, debug=True)
        
        if not hit_info.hit:
            v += G
            body.y -= v
        else:
            v = 0
        new_bodies.add((body, v))
    bodies = new_bodies

EditorCamera()
DirectionalLight(parent=Entity(), y=2, z=3, shadows=True, rotation=(45, -45, 45))

app.run()

I'm trying to set up a gravity system in the update function which actually applies uniformly on the object, unlike (from what I can tell) the firstpersoncontroller one already built in. The easiest way I can think of doing this is by raycasting down from each of the vertices (so that it works for objects which aren't just cubes).

Is there a way to find the vertices of the entity? I've tried body.model.vertices but that gives me an error (AttributeError: 'panda3d.core.NodePath' object has no attribute 'vertices') saying that the function doesn't exist.

If not, is there an easier way to implement gravity? My main problem with the existing ways is that they all end up with something like this: Cube on vertex when in reality the cube should just fall to the floor.

Thank you in advance.

1

There are 1 answers

0
Raphi-2Code On

Just use:

body.combine().vertices