add move speed
This commit is contained in:
+4
-2
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user