add move speed

This commit is contained in:
2024-12-22 17:00:23 +09:00
parent 69343821b6
commit 14212afd70
4 changed files with 8 additions and 3 deletions
+1
View File
@@ -22,6 +22,7 @@
html, body { html, body {
margin: 0; margin: 0;
padding: 0; padding: 0;
user-select: none;
} }
.debug-panel { .debug-panel {
+1 -1
View File
@@ -20,7 +20,7 @@ scene.add(ground)
global.camera = camera global.camera = camera
global.scene = scene global.scene = scene
camera.position.set(0, -100, 200) camera.position.set(0, -250, 500)
camera.rotation.set((30 / 180) * Math.PI, 0, 0) camera.rotation.set((30 / 180) * Math.PI, 0, 0)
// camera.lookAt(0, 0, 0) // camera.lookAt(0, 0, 0)
+4 -2
View File
@@ -4,6 +4,7 @@ import Victor from 'victor'
export default class Entity { export default class Entity {
id = crypto.randomUUID() id = crypto.randomUUID()
pos = new Victor(0, 0) pos = new Victor(0, 0)
speed = 280
radius = 0 radius = 0
#collider = null #collider = null
#dest = null #dest = null
@@ -24,9 +25,10 @@ export default class Entity {
} }
async takeStep() { async takeStep() {
const speed = this.speed / (this.game?.tickBudget ?? 1000)
if (this.#dest != null) { if (this.#dest != null) {
this.pos.add(this.#dest.clone().subtract(this.pos).normalize()) this.pos.add(this.#dest.clone().subtract(this.pos).normalize().multiplyScalar(speed))
if (this.pos.clone().subtract(this.#dest).length() <= 1) { if (this.pos.clone().subtract(this.#dest).length() <= speed) {
this.pos = this.#dest this.pos = this.#dest
this.#dest = null this.#dest = null
} }
+2
View File
@@ -12,10 +12,12 @@ export default class Game {
get eventEmitter() { return this.#eventEmitter } get eventEmitter() { return this.#eventEmitter }
get system() { return this.#system } get system() { return this.#system }
get tickBudget() { return this.#tickBudget }
spawn_entity(entity) { spawn_entity(entity) {
this.entities.push(entity) this.entities.push(entity)
this.#system.insert(entity.collider) this.#system.insert(entity.collider)
entity.game = this
} }
async start() { async start() {