Locally I can use dragControls.addDragEventListener(âselectendâ, func) by adding // @ts-ignore
When I upload to glitch I am getting a type script error
Uncaught TypeError: Cannot read properties of undefined (reading âaddDragEventListenerâ)
What is the proper way to add event listener to drag controls, when I use the addeventlistener function it doesnât do anything
if(dragControls) {
//dragControls.addDragEventListener(âselectendâ, func) ?
dragControls.addEventListener(âselectendâ, func) ?
}
Original Post on Discord
by user 931365436187111505
How are those dragControls referenced / how do you assign them?
Your code looks fine, looks rather like âwherever dragControls comes fromâ might be incorrect
const dragControls = GameObject.getComponent(this.gameObject, DragControls)
const func = () => {
console.log(âDrag Ended!â)
this.gameObject.position.set(this.currentCubeBelow.position.x,
this.gameObject.position.y,
this.currentCubeBelow.position.z)
this.selectEndEventListener = 0;
}
if(this.selectEndEventListener==0) {
if(dragControls) {
//dragControls.addDragEventListener("selectend", func)
dragControls.addEventListener("selectend", func)
console.log(dragControls)
}
this.selectEndEventListener = 1;
}
by user 931365436187111505
trying to get the cactus to snap to the center of the tile when i stop dragging
by user 931365436187111505
This
const dragControls = GameObject.getComponent(this.gameObject, DragControls)
should be fine â how are you importing DragControls?
Also, could you clarify what addDragEventListener
is? I donât think that exists, you should probably use addEventListener(dragstart) and so on
wait that is probably it, iâm not importing dragcontrols from the right location, it was importing from - import {DragControls} from âthree/examples/jsm/controls/DragControlsâ;
by user 931365436187111505
there is a class DragControls with method - addDragEventListener in the engine/engine-components folder
by user 931365436187111505
should I be importing that class?
by user 931365436187111505
works now, thank!
by user 931365436187111505
OK great! Sorry for the confusion