fix pathfinding issues

This commit is contained in:
2025-01-12 19:43:45 +09:00
parent 6ff950640c
commit 8e861929cb
6 changed files with 385 additions and 158 deletions
+17
View File
@@ -6,11 +6,14 @@ const scene = new THREE.Scene()
const raycaster = new THREE.Raycaster()
const camera = new THREE.PerspectiveCamera(30, window.innerWidth / window.innerHeight, 0.1, 1000)
const renderer = new THREE.WebGLRenderer()
const backgroundColor = new THREE.Color().setHex(0x112233)
scene.background = backgroundColor
renderer.setSize(window.innerWidth, window.innerHeight)
renderer.setAnimationLoop(render)
camera.position.set(5, -12, 10)
camera.rotation.set((60 / 180) * Math.PI, 0, 0)
camera.layers.enable(1)
camera.layers.enable(2)
const entityMaterial = new THREE.MeshToonMaterial({ color: 0xffffff })
const projectileMaterial = new THREE.MeshToonMaterial({ color: 0xff00ff })
@@ -159,6 +162,10 @@ function connectWebSocket() {
ground.position.set(state.width / 200, state.height / 200, 0)
}
for (const e of Object.values(entities)) {
e.userData.flaggedForRemoval = true
}
for (const e of state.entities ?? []) {
let entity
if (e.id in entities) {
@@ -190,6 +197,7 @@ function connectWebSocket() {
entities[e.id] = entity
}
entity.userData.flaggedForRemoval = false
positionTweens[entity.id] = new Tween(entity.position).to({ x: e.position.x / 100, y: e.position.y / 100, z: e.radius / 100 }, tweenDuration).start()
const hp = entity.children.at(0).children.at(0)
@@ -198,6 +206,14 @@ function connectWebSocket() {
hp.position.x = -(1 - percentageHp) / 2
}
for (const e of Object.values(entities)) {
if (e.userData.flaggedForRemoval) {
scene.remove(e)
delete entities[e.userData.id]
delete positionTweens[e.userData.id]
}
}
for (const p of Object.values(projectiles)) {
p.userData.flaggedForRemoval = true
}
@@ -212,6 +228,7 @@ function connectWebSocket() {
projectile.userData.type = 'projectile'
projectile.userData.id = p.id
projectile.position.set(p.position.x / 100, p.position.y / 100, p.visualHeight / 100)
projectile.layers.set(2)
scene.add(projectile)
projectiles[p.id] = projectile