fix neighs undefined by different lookup method

This commit is contained in:
Marius Unsel 2026-02-23 02:42:58 +01:00
parent 33876d44d5
commit 1c9e4d5aa4

View File

@ -64,6 +64,10 @@ export class Player {
this.model.position.set(v.x, v.y, v.z + 1)
}
findVoxelByPos(x: number, y: number, z: number): Voxel | undefined {
return this.voxels.find(v => v.x === x && v.y === y && v.z === z)
}
reset() {
this.voxelStandingOn = this.voxels[this.level.playerPos.voxelIdx]
this.setToVoxelPosition(this.voxelStandingOn)
@ -114,13 +118,23 @@ export class Player {
}
jump() {
if (!this.voxelStandingOn?.neighs) {
this.doneAnimating()
return
}
let x0 = this.voxelStandingOn
let nextVoxel = this.voxelStandingOn.neighs[this.direction]
if (nextVoxel["up"]) {
this.voxelStandingOn = nextVoxel["up"]
const targetX = nextVoxel["up"].x
const targetY = nextVoxel["up"].y
const targetZ = nextVoxel["up"].z
this.voxelStandingOn = this.findVoxelByPos(targetX, targetY, targetZ) || nextVoxel["up"]
}
if (nextVoxel["down"]) {
this.voxelStandingOn = nextVoxel["down"]
const targetX = nextVoxel["down"].x
const targetY = nextVoxel["down"].y
const targetZ = nextVoxel["down"].z
this.voxelStandingOn = this.findVoxelByPos(targetX, targetY, targetZ) || nextVoxel["down"]
}
this.actions['Jump'].reset()
this.actions['Jump'].play()
@ -157,9 +171,16 @@ export class Player {
}
forward() {
if (!this.voxelStandingOn?.neighs) {
this.doneAnimating()
return
}
let nextVoxel = this.voxelStandingOn.neighs[this.direction]
if (nextVoxel["forward"]) {
this.voxelStandingOn = nextVoxel["forward"]
const targetX = nextVoxel["forward"].x
const targetY = nextVoxel["forward"].y
const targetZ = nextVoxel["forward"].z
this.voxelStandingOn = this.findVoxelByPos(targetX, targetY, targetZ) || nextVoxel["forward"]
let x = this.model.position.x
let y = this.model.position.y
this.actions['Walking'].reset()