Hi, So I’m trying to create a constant raycaster to a plane/flat surface that sets a object’s position and rotation based on the device screen size and orientation and for some reason the object won’t place itself at the camera point I’m pointing to. I tried using the logic from this project, Place Vertical Surface | 8th Wall | 8th Wall but it doesn’t seem to work. Here is my code:
//raycast from center of screen
let spot = new THREE.Vector3()
let tempCenter = new THREE.Vector2()
const tempRaycast = new THREE.Raycaster()
tempCenter.x = window.innerWidth
tempCenter.y = window.innerHeight
tempRaycast.setFromCamera(tempCenter,world.three.activeCamera)
const tempGround = world.three.entityToObject.get(SpawnFloor)
const hits = tempRaycast.intersectObject(tempGround,true)
if(hits.length > 0)
{
spot = hits[0].point
}
setComponent(SpawnCursor, 'Position', {x: spot.x, y: spot.y, z: spot.z}, world)
//world.setPosition(SpawnCursor, spot)
//world.setQuaternion(SpawnCursor,world.three.activeCamera)
console.log('cursor:' + ecs.Position.get(world, SpawnCursor).x + ecs.Position.get(world, SpawnCursor).y + ecs.Position.get(world, SpawnCursor).z)
Any help would be appreciated!
- Leonard