Mouse Collision

Handling mouse-based collision detection and click events in Ursina Engine.

Mouse Collision

The mouse performs a raycast each frame. Useful attributes:

  • mouse.hovered_entity
  • mouse.point / mouse.world_point
  • mouse.normal / mouse.world_normal

Add a collider and on_click handler:

def action():
    print('Ow! That hurt!')

Entity(
    model='quad',
    parent=camera.ui,
    scale=0.1,
    collider='box',
    on_click=action
)