Skip to content

The raycaster's line (when showLine is true) is not accurate when the raycaster's origin is not (0, 0, 0) #4882

@Clicky02

Description

@Clicky02

Description: When a raycaster has an origin other than (0, 0, 0), the line it creates will not accurately show the path of the raycast.

  • A-Frame Version: 1.2.0
  • Platform / Device: Should apply to all platforms/devices, but tested in Firefox 89
  • Reproducible Code Snippet or URL:

There are two blocks of code responsible for this (both in raycaster.js)

The first is in the update function.
image
The key part here is that it sets unitLineEndVec3 to the unit vector of the sum of the origin and direction vectors.

The second is the drawLine function.
image
The key part here is the end point for the line uses the unitLineEndVec3 variable from before. Essentially it sets the line's end point to:

normalize(origin + direction) * scalarLength

Instead, it should set the end point to something equivalent to:

origin + (normalize(direction) * scalarLength)

When the origin is 0,0,0, these two are exactly the same, but when the origin is anything else, the line is not accurate to the raycaster. For example, imagine a raycaster with its origin at (30, 0, 0) and a direction of (0, 1, 0) that is intersecting with something 1 unit away at (30, 1, 0). The unitLineEndVec3 variable would be set to a unit vector that is mostly in the +x direction. Then, the line's start would be set to the origin (which is correct), but the line's end would be set to something around (1, 0, 0), which is nowhere near where the actual raycaster is intersecting.

In my case, I am using the raycaster component with oculus controller model for interacting with a menu. By default, the raycaster is not placed at the origin. So, when the menu is close to the user, there is a notable disconnect from the raycaster's end and the menu's surface. Additionally, when the intersection begins you can see the direction of the line shift.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions