add move speed
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
html, body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.debug-panel {
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ scene.add(ground)
|
||||
|
||||
global.camera = camera
|
||||
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.lookAt(0, 0, 0)
|
||||
|
||||
|
||||
+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
|
||||
}
|
||||
|
||||
@@ -12,10 +12,12 @@ export default class Game {
|
||||
|
||||
get eventEmitter() { return this.#eventEmitter }
|
||||
get system() { return this.#system }
|
||||
get tickBudget() { return this.#tickBudget }
|
||||
|
||||
spawn_entity(entity) {
|
||||
this.entities.push(entity)
|
||||
this.#system.insert(entity.collider)
|
||||
entity.game = this
|
||||
}
|
||||
|
||||
async start() {
|
||||
|
||||
Reference in New Issue
Block a user