Works perfectly on PC, but on Mobile, the following barely works. Sometimes I can get a click to register, but rarely. Clicking in random spots doesn’t seem to register other objects, so I’ve assumed that maybe it isn’t an X/Y issue. Any examples on this? (Note the touchend event at the end)
I’m probably doing something silly, and just need to test more to realize what it is. Hoping someone might just point out my stupid though
let ilist = []
const raycaster = new THREE.Raycaster()
const pointer = new THREE.Vector2(),
domClick = ((e)=>{
pointer.x = ( e.clientX / window.innerWidth ) * 2 - 1
pointer.y = - ( e.clientY / window.innerHeight ) * 2 + 1
raycaster.setFromCamera( pointer, camera )
const intersects = raycaster.intersectObjects( scene.children )
toploop: for ( let i = 0; i < intersects.length; i ++ ) {
let obj = intersects[ i ].object
for ( let key in pobjs ) {
if ( pobjs[key].id == obj.id ) {
if ( key == 'MC' ) {
console.log( "'" + ilist.join("', '") + "'" )
ilist = []
} else {
ilist.push( key )
}
console.log( "CLICKED: '" + key + "'" )
//alert('Clicked ' + key)
break toploop
}
}
}
})
renderer.domElement.addEventListener("click", domClick)
renderer.domElement.addEventListener("touchend", domClick)
Although its the child of a DIV, the width is set to 100% and height is set to 100vh. It perfectly sizes. Turning phone vertical or horizontal flips proportionately, no scroll bar and it fills completely. (In the future it won’t be filling the entire screen, but since it currently is I figured this should scale correctly and the same compared to desktop)
Thanks I’ll do some research and play with it! Haven’t really done much mobile stuff at all, and although it’s not a priority atm, I want to make sure I can interact with objects on the canvas for this project on mobile in the future.
Ahhhh duh, this was it. Thanks! I completely forgot about e.touches, was just playing with them in February, and on the project this is being implemented into lol.
Final solution, as this won’t use 100% width / height, and can move.