HitInfo

Stores detailed information about a collision, including hit status, entity, contact points, normals, and distance.

HitInfo

HitInfo(**kwargs)

Located in ursina/hit_info.py

Overview

HitInfo is returned by collision detection functions (such as raycast or boxcast). It indicates whether a collision occurred and provides details about the hit point, normals, distance from origin, and involved entities.

Constructor Arguments

ArgumentTypeDefaultDescription
hitboolNoneWhether a collision occurred (True) or not (False).
entityEntityNoneThe first entity that was hit.
pointVec3NoneCollision point in the entity’s local coordinate space.
world_pointVec3NoneCollision point in world coordinates.
distancefloat9999Distance from the origin of the test (ray or box) to the collision point.
normalVec3NoneSurface normal at the collision location in local space.
world_normalVec3NoneSurface normal at the collision location in world space.
hitslist[]For multi-hit queries, list of HitInfo instances for each collision.
entitieslist[]List of all entities hit (in case multiple collisions occur).

Properties

PropertyDescription
.hitTrue if a collision occurred; otherwise False.
.entityThe first entity that was hit.
.pointCollision point in the entity’s local space.
.world_pointCollision point in world coordinates.
.distanceDistance from the origin of the test to the hit point.
.normalSurface normal at the collision location in local space.
.world_normalSurface normal at the collision location in world space.
.hitsList of HitInfo for each collision in multi-hit scenarios.
.entitiesList of entities hit when multiple collisions occur.

Methods

MethodDescription
__bool__()Returns the value of .hit, enabling if hit_info: style collision checks.

Example

from ursina import Ursina, raycast, Vec3
from ursina.hit_info import HitInfo

app = Ursina()

# Cast a ray downward from (0, 5, 0)
hit = raycast(origin=Vec3(0,5,0), direction=Vec3(0,-1,0), distance=10)

if hit:
    print('Hit entity:', hit.entity)
    print('Collision point (world):', hit.world_point)
    print('Surface normal (world):', hit.world_normal)
    print('Distance to hit:', hit.distance)
else:
    print('No collision within 10 units')

app.run()