Movement copied from the minecraft wiki :3

This commit is contained in:
2026-09-28 12:01:51 -03:00
parent ded9a7e5d0
commit 036f8075f5
5 changed files with 189 additions and 12 deletions
+15 -3
View File
@@ -82,20 +82,32 @@ export abstract class Entity {
return this.eye_height;
}
// how much wider the view is from its eyes, like minecraft widening it while sprinting
render_fov_scale(_partial_tick: number) {
return 1;
}
// one step of the game, TICK_DELTA seconds
abstract tick(): void;
// falls and moves by its velocity for one tick (see move_body), then slows down from drag
// what's left of its sideways speed after each tick, from where it was at the start of the tick like minecraft,
// so the tick it jumps still has the ground's friction
horizontal_friction() {
return this.drag;
}
// falls and moves by its velocity for one tick (see move_body), then slows down from drag and friction
move() {
const is_solid = (x: number, y: number, z: number) => this.level.has_collision(x, y, z);
const can_step = this.#air_ticks <= this.step_grace_ticks && this.vy <= 0;
const friction = this.horizontal_friction();
const collisions = move_body(this, this.gravity, is_solid, this.step_height, can_step);
this.colliding_x = collisions.x;
this.colliding_y = collisions.y;
this.colliding_z = collisions.z;
this.#air_ticks = this.on_ground ? 0 : this.#air_ticks + 1;
this.vx *= this.drag;
this.vx *= friction;
this.vy *= this.drag;
this.vz *= this.drag;
this.vz *= friction;
}
}