- Error Type: The zombie entity is being created in the hierarchy but is not visible in the scene.
- Related Errors:
- When using
ecs.GltfModel.set
, the following error is logged:
Unhandled promise rejection: SyntaxError: Unexpected token '<', "<?xml vers"... is not valid JSON
import * as ecs from '@8thwall/ecs'
import {generateRandomPositionInRadius} from '../helpers/position'
/**
* ZOMBIE
*/
export const Zombie = ecs.registerComponent({
name: 'Zombie',
schema: {
// @asset
zombieAsset: ecs.string,
animationClip: ecs.string,
},
schemaDefaults: {
// Default zombie model
zombieAsset: 'https://tidsarstudio-default-thisisdivakar.dev.8thwall.app/assets/models/zombie.glb',
animationClip: 'Idle',
},
add: (world, component) => {
const {eid, schema: {zombieAsset, animationClip}} = component
const applyRandomPositionToZombie = () => {
// Calculate a new random position given a radius
const {x, y, z} = generateRandomPositionInRadius(15, {minDistFromOrigin: 3, initialY: 0})
// Assign the random position to the zombie
const zombiePosition = ecs.Position.cursor(world, eid)
zombiePosition.x = x
zombiePosition.y = y
zombiePosition.z = z
}
// Set the zombie model to the entity
ecs.GltfModel.set(world, eid, {
url: zombieAsset,
animationClip: 'Idle',
loop: true,
paused: false,
time: 0,
timeScale: 1,
})
// Add an event listener for when the model loads
world.events.addListener(eid, ecs.events.GLTF_MODEL_LOADED, applyRandomPositionToZombie)
},
remove: (world, component) => {
// Cleanup logic if needed
},
tick: (world, component) => {
// Handle any per-frame updates for the zombie if needed
},
})
[/grid]