Replies: 1 comment 1 reply
-
Hello! Seems you are pretty close, here is an example that should work let plane = new PIXI3D.Plane(new Float32Array([0, 1, 0]), 0.8)
document.addEventListener("mousemove", e => {
let ray = PIXI3D.Camera.main.screenToRay(e.x, e.y)
let distance = plane.rayCast(ray)
let point = ray.getPoint(distance)
// model is my 3d object
model.position.array = point
}) I should improve the docs for this. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I posted this on stackoverflow but it's not getting a lot of attention so I'll try here.
I'm trying to get raycasting to work in. However the documentation is not very helpful to me.
What I am trying to do is make a 3d object follow the mouse coordinates on a 3d plane in space.
This is what I've come up with:
First I've created the plane:
let normalTest = new Float32Array(3);
normalTest[0] = 0;
normalTest[1] = 0;
normalTest[2] = 1;
planeTest = new Plane(normalTest, 100);
Then in my loop I try to get a ray to intersect the plane:
let ray = Camera.main.screenToRay(mouseX(), mouseY(), {height: 1920, width: 1080 });
if(ray != undefined){
let rayRes = planeTest.rayCast(ray);
let rayPoint = ray.getPoint(planeTest.rayCast(ray));
myBlackBox.x = rayPoint[0];
myBlackBox.y = (-l.mouseY()/100);
}
But I don't really understand how to use the ray object. How do I know if the ray has intersected the plane?
Beta Was this translation helpful? Give feedback.
All reactions