Hi there,
I’ve been trying to get this logic to spawn multiple .glb models when I tap the ground, but so far I’ve been struggling to make this happen, as it seems that everytime it always spawns the model that is referenced later in the code, ignoring everything behind it.
I’m new to this language so I’m not sure where the logic stops making sense. :S
Does anyone have any suggestions?
This is what I have it set to atm:
// Component that places Jakes where the ground is clicked
export const tapPlaceComponent = {
init() {
const ground = document.getElementById('ground')
ground.addEventListener('click', (event) => {
// Create new entity for the new object
const newElement = document.createElement('a-entity')
// The raycaster gives a location of the touch in the scene
const touchPoint = event.detail.intersection.point
newElement.setAttribute('position', touchPoint)
const randomYRotation = Math.random() * 360
newElement.setAttribute('rotation', `0 ${randomYRotation} 0`)
newElement.setAttribute('visible', 'false')
newElement.setAttribute('scale', '0.0001 0.0001 0.0001')
newElement.setAttribute('shadow', {
receive: false,
})
newElement.setAttribute('gltf-model', '#JakeModel')
newElement.setAttribute('gltf-model', '#FinnModel')
this.el.sceneEl.appendChild(newElement)
newElement.addEventListener('model-loaded', () => {
// Once the model is loaded, we are ready to show it popping in using an animation
newElement.setAttribute('visible', 'true')
newElement.setAttribute('animation', {
property: 'scale',
to: '7 7 7',
easing: 'easeOutElastic',
dur: 800,
})
})
})
},
}