# Raycast intersectObjects on group returns every element in the group, not the raycast target

**URL:** <https://discourse.threejs.org/t/raycast-intersectobjects-on-group-returns-every-element-in-the-group-not-the-raycast-target/67062>\
**Category:** Questions\
**Tags:** drag-controls\
**Created:** [June 20, 2024, 3:53am UTC](https://discourse.threejs.org/t/raycast-intersectobjects-on-group-returns-every-element-in-the-group-not-the-raycast-target/67062 "2024-06-20T03:53:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Metaphoresy](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/metaphoresy/32/38185_2.png) [@Metaphoresy](https://discourse.threejs.org/u/Metaphoresy)\
**Post date:** [June 20, 2024, 3:53am UTC](https://discourse.threejs.org/t/raycast-intersectobjects-on-group-returns-every-element-in-the-group-not-the-raycast-target/67062/1 "2024-06-20T03:53:18Z")

</div>

I’m not sure if it’s intended behavior or what I’m missing. I can get this to work in the “mousedown” event, but not by raycasting from the mouse in the DragControls “dragend” event.

```javascript
var mouse = new THREE.Vector2();
mouse.x = (event.clientX / renderer.domElement.clientWidth) * 2 - 1;
mouse.y = - (event.clientY / renderer.domElement.clientHeight) * 2 + 1;

let raycaster = new THREE.Raycaster();
raycaster.near = 0;
raycaster.far = 100;

raycaster.setFromCamera(mouse, camera)

const intersects = raycaster.intersectObjects(slots, false);

for (let i = 0; i < intersects.length; i++) {
	let mesh = intersects[i];
	if (mesh.object.userData) {
		console.log(mesh.object.userData);
		return;
	}
}

```

The “slots” variable is a simple array of meshes added when I create the inventory UI elements. I’m attempting to drag my items’ meshes to slots in an inventory system.I’m trying to get the inventory slot mesh under the mouse when the dragend event ends.

Is there an obvious reason why it always returns the entire group, while mouse clicks return the intersected element correctly?

Any help would be appreciated.

---

<div class="post-metadata">

**Author:** ![iHast](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/ihast/32/34649_2.png) [@iHast](https://discourse.threejs.org/u/iHast)\
**Post date:** [June 22, 2024, 3:42am UTC](https://discourse.threejs.org/t/raycast-intersectobjects-on-group-returns-every-element-in-the-group-not-the-raycast-target/67062/2 "2024-06-22T03:42:28Z")

</div>

Can you share the complete code related to this problem? Codepen, JSFiddle or here. I don’t understood how you created your group. Are you using: [three.js docs](https://threejs.org/docs/index.html?q=group#api/en/objects/Group) and relating the event to this group?
