aframe Raycasters (component) Setting the Origin and Direction of the Raycaster


Example

The raycaster has an origin, where its ray starts, and a direction, where the ray goes.

The origin of the raycaster is at the raycaster entity’s position. We can change the origin of the raycaster by setting the position component of the raycaster entity (or parent entities of the raycaster entity).

The direction of the raycaster is in “front” of the raycaster entity (i.e., 0 0 -1, on the negative Z-axis). We can change the direction of the raycaster by setting the rotation component of the raycaster entity (or parent entities of the raycaster entity).

For example, here is applying a raycaster along the length of a rotated bullet:

<!-- Bullet, rotated to be parallel with the ground. -->
<a-entity id="bullet" geometry="primitive: cylinder; height: 0.1" rotation="-90 0 0">
  <!-- Raycaster, targets enemies, made to be as long as the bullet, positioned to the start of the bullet, rotated to align with the bullet. -->
  <a-entity raycaster="objects: .enemies; far: 0.1" position="0 -0.5 0" rotation="90 0 0"></a-entity>
</a-entity>