Skip to content

Instantly share code, notes, and snippets.

@Badestrand
Last active April 18, 2022 04:41
Show Gist options
  • Save Badestrand/b63474f5d1194c7132a7c264a843cba3 to your computer and use it in GitHub Desktop.
Save Badestrand/b63474f5d1194c7132a7c264a843cba3 to your computer and use it in GitHub Desktop.
class Enemy {
tick(deltaTime) {
...
const thisAabb = new THREE.Box3().setFromObject(this.mesh)
for (const projectile of allProjectiles) {
const projectileAabb = new THREE.Box3().setFromObject(projectile.mesh)
if (thisAabb.intersectsBox(projectileAabb)) {
spawnParticles(projectile.mesh.position.clone(), 5, Colors.brownDark, 1)
projectile.remove()
this.hitpoints -= projectile.damage
}
}
if (this.hitpoints <= 0) {
this.explode()
}
}
explode() {
spawnParticles(this.mesh.position.clone(), 15, Colors.red, 3)
sceneManager.remove(this)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment