Boxcast

Cast a swept box (thick ray) to detect collisions.

Boxcast

boxcast(origin, direction=(0,0,1), distance=9999, thickness=(1,1), traverse_target=scene, ignore=None, debug=False)

Similar to raycast but with a rectangular cross‑section defined by thickness.

Parameters

NameTypeDefaultDescription
originVec3Starting point.
directionVec3(0,0,1)Direction vector.
distancefloat9999Maximum travel distance.
thickness(float,float)(1,1)Width and height of the box cross‑section.
traverse_targetEntitysceneParent to search under.
ignorelist[Entity]NoneEntities to exclude.
debugboolFalseDraw the box path if True.

Example

from ursina import *
from ursina.boxcast import boxcast

app = Ursina()

class Player(Entity):
    def update(self):
        dir = Vec3(held_keys['d'] - held_keys['a'], 0, held_keys['w'] - held_keys['s']).normalized()
        start = self.world_position + (self.up * .5)
        hit = boxcast(start, dir, distance=.5, thickness=(.5,.5), ignore=[self])
        if not hit.hit:
            self.position += dir * time.dt * 5

Player(model='cube', origin_y=-.5, color=color.orange)
wall = Entity(model='cube', collider='box', scale=(1,3,1), origin_y=-.5, color=color.azure, x=3)
EditorCamera()
app.run()