pookeeshtron
pookeeshtron

Reputation: 135

Is there any way to give an offset to raycaster three.js?

I am trying to make a pool game in three.js. I have a helper ruler that shows the direction of hit. It's an ArrowHelper that is located in y=0 same as my raycaster to detect borders. But I also need it to detect a ball which center is upper than y=0. It's on y = 0.35. And I am wondering how to displace my raycaster upper in scene, so it can also detect my ball. Is there any way to displace my raycaster in y?

Upvotes: 0

Views: 106

Answers (1)

M -
M -

Reputation: 28492

If you know the origin and direction of your raycaster in 3D space, you can simply use raycaster.set() because it lets you specify both attributes, just make sure your direction is always normalized (total magnitude = 1):

let origin = new THREE.Vector3(x1, y1, z1);
origin.y += 0.35;
let direction = new THREE.Vector3(x2, y2, z2);
raycaster.set(origin, direction.normalize());

Upvotes: 1

Related Questions