Rays - ZackWilde27/Z3dPy GitHub Wiki

z3dpy.Ray(vStartPos, vEndPos, *isArrow)

Rays are used for debugging, and collisions.

start = myCamera.position
end = myCharacter.position

myRay = z3dpy.Ray(start, end)

print(z3dpy.RayGetDirection(myRay))

Drawing

To draw rays, add them to the internal rays list, and they will be drawn with DebugRender()

# Rays in the global list will be drawn with DebugRender()
z3dpy.rays.append(myRay)

for tri in z3dpy.DebugRender():
    canvas.create_polygon([tri[0][0], tri[0][1], tri[1][0], tri[1][1], tri[2][0], tri[2][1]], fill=zp.RGBToHex(zp.TriGetColour(tri)))

In 0.2.8+, rays now have isArrow, which will draw the ray as an arrow pointing at the end location.

myRay = z3dpy.Ray(start, end, True)

Collisions

For collisions, use RayIntersect functions.

# Simple checks for collisions against the hitbox of the Thing
hit = z3dpy.RayIntersectThingSimple(myRay, myCharacter)
# Hit: [0] is wether or not it hit. [1] is location, [2] is distance, [3] is the normal of the hit, and [4] is the triangle that was hit.
if hit[0]:
    print(hit[1])

# Complex checks for collisions against each triangle of each mesh of the Thing
hit = z3dpy.RayIntersectThingComplex(myRay, thatTree)
if hit[0]:
    print(hit[2])

hit = z3dpy.RayIntersectMesh(myRay, myMesh)
if hit[0]:
    print(hit[3])

hit = z3dpy.RayIntersectTri(myRay, thatTri)
if hit[0]:
    print("Yep")