Send a ray from the raycaster and get the intersection with the plane. This intersection contains many data, one of which is the exact 3D position of the intersection point. You can use it to position a cube there.
response = Vector3 {x: 2, y: 0, z: 0.5804248372069998}
but this is not exact position where I clicked.
Probably is problem in intersetcObject, because there is some kind of children and I want only “Plane”
I tried this but doesn’t working
@Wynnyy Would be better to provide the model you use, if possible. Or provide a live code example (jsfiddle, codepen, codesandbox), that demonstrates the issue.
can you provide the game.gltf file in this thread? with a bit of modification to make your code compatible with codepen the intersectsObject method seems to work fine with a plane exported from blender…
np I think it may have just been a misundrestanding of what intersectsObject does, it takes in one object to raycast against but still returns an array of intersections ( this is incase recursive is set to true and the object in question has a multitude of child elements ) in your case I’m sure the error was simply because you were not checking if ( intersects.length > 0 ){ } eg in the following code from your pen…
there were a few other issues in your code, for instance you created your click event listener inside your animation loop, in essence creating a click event every frame will result in a huge memory leak, as well as creating raycaster, mousePosition, cube, plane, draggable in the same loop, these elements can be created once a reused, especially the click event!
Hi @Lawrence3DPK anyway similar problem ,is much better but when I click on corner or another place ,my cube is not on exact position.Idk what can have impact on this, render size ,maybe another things. here for example
is your containers element the full size of the window or a smaller sized container? if it’s smaller then you’d need to use the following in the click event…
this is also why it’s useful to have a live working example in codesandbox or codepen, if the container is smaller than the window and has margins then you’d also need to account for the offsetTop and offsetLeft of the container to get accurate raycasting…
yeah see that,
this.mousePosition.x = (e.clientX / widthh) * 2 - 1;
this.mousePosition.y = -(e.clientY / heightt) * 2 + 1;
doesnt fix my problem,but every margin have impact on this position, also camera position have impact