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
+4 -2
View File
@@ -4,6 +4,7 @@ import Victor from 'victor'
export default class Entity {
id = crypto.randomUUID()
pos = new Victor(0, 0)
speed = 280
radius = 0
#collider = null
#dest = null
@@ -24,9 +25,10 @@ export default class Entity {
}
async takeStep() {
const speed = this.speed / (this.game?.tickBudget ?? 1000)
if (this.#dest != null) {
this.pos.add(this.#dest.clone().subtract(this.pos).normalize())
if (this.pos.clone().subtract(this.#dest).length() <= 1) {
this.pos.add(this.#dest.clone().subtract(this.pos).normalize().multiplyScalar(speed))
if (this.pos.clone().subtract(this.#dest).length() <= speed) {
this.pos = this.#dest
this.#dest = null
}