🔦 Raycast#
#bs.raycast:help
Cast rays and see if they collide with blocks or entities.
Note
Unlike traditional raycasts, this module uses a voxel traversal algorithm which is a lot more precise. Also, thanks to the bs.hitbox
module, it supports all different hitboxes, including both blocks & entities.
“Reality only reveals itself when it is illuminated by a ray of poetry.”
—Georges Braque
🔧 Functions#
You can find below all functions available in this module.
Run the raycast#
- #bs.raycast:run {with:{}}
Cast a ray from the execution position and check if it hits something.
- Inputs:
Execution
at <entity>
orpositioned <x> <y> <z> rotated <rot>
: Origin of the ray.Function macro:
- Arguments
- with: Ray input data.
- blocks: Whether the ray should stop on blocks (default: true).
- entities: Whether the ray should stop on entities (default: false). Can also be a required entity tag.
- piercing: Number of blocks or entities the ray can pass through (default: 0).
- max_distance: Maximum ray travel distance (default: 16.0).
- ignored_blocks: Blocks to ignore (default:
#bs.hitbox:intangible
). - ignored_entities: Entities to ignore (default:
#bs.hitbox:intangible
). - on_hit_point: Command to run at the exact point where the ray makes contact.
- on_targeted_block: Command to run at the block hit by the ray.
- on_targeted_entity: Command to run as and at the entity hit by the ray.
- with: Ray input data.
- Arguments
- Outputs:
Return: Whether the ray collides with a hitbox or not (1 or 0).
Storage
bs:out raycast
:- Ray output data
- distance: The distance from the ray’s origin to the impact point.
- hit_point: The coordintates of the impact point.
- hit_normal: The normal of the surface the ray hit.
- targeted_block: The coordinates of the block that was hit.
- targeted_entity: The UUID array of the entity that was hit.
- Ray output data
Cast a ray from your eyes and see, if it stopped, where it stopped:
# Once (return 0 if no collision occured)
execute anchored eyes positioned ^ ^ ^ run function #bs.raycast:run {with:{}}
# If a collision occured, see the collision point
data get storage bs:out raycast.hit_point
Credits: Aksiome
💬 Did it help you?
Feel free to leave your questions and feedbacks below!