Сейчас ловлю только пересечение с родителем:
scene.registerBeforeRender(function () {
console.log(enemy)
if (enemy.intersectsMesh(player)) {
player.material.emissiveColor = new BABYLON.Color3(1, 0, 0);
//console.log('Задел')
} else {
player.material.emissiveColor = new BABYLON.Color3(1, 1, 1);
//console.log('Мимо')
}
})
Создаю инстасы так:
let enemy = BABYLON.MeshBuilder.CreateBox("enemy", {})
enemy.material = enemyMat
enemy.position.z = 70
enemy.position.y = 0.3
enemy.animations.push(standartFrameRateEnemy())
let enemyAnim = scene.beginAnimation(enemy, 0, 11, true)
for (let i = 0; i < 20; i++) {
let newEnemy = enemy.createInstance("enemy" + i);
newEnemy.position.x = randomPositionX()
setTimeout(() => {
newEnemy.animations.push(standartFrameRateEnemy())
let enemyAnim = scene.beginAnimation(newEnemy, 0, 11, true)
}, 2700 * i)
}