Improve moviment !
This commit is contained in:
+15
-1
@@ -30,6 +30,12 @@ export abstract class Entity {
|
||||
// what's left of its speed after each tick in the air, like minecraft's 0.98. it caps falling speed
|
||||
// at 49 * -gravity * TICK_DELTA, 78 blocks per second with minecraft's gravity
|
||||
drag = 0.98;
|
||||
// what it walks up onto without jumping, see move_body
|
||||
step_height = 0;
|
||||
// it can still step up this many ticks after leaving the ground
|
||||
step_grace_ticks = 0;
|
||||
// ticks since it was last on the ground
|
||||
#air_ticks = 0;
|
||||
|
||||
// which way it hit something on each axis in the last move: 1 or -1, 0 for nothing.
|
||||
// 1 on y means it's standing on something
|
||||
@@ -71,15 +77,23 @@ export abstract class Entity {
|
||||
};
|
||||
}
|
||||
|
||||
// how high the eyes are, for the camera. a frame is partial_tick of the way to the next tick
|
||||
render_eye_height(_partial_tick: number) {
|
||||
return this.eye_height;
|
||||
}
|
||||
|
||||
// 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
|
||||
move() {
|
||||
const collisions = move_body(this, this.gravity, (x, y, z) => this.level.has_collision(x, y, z));
|
||||
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 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.vy *= this.drag;
|
||||
this.vz *= this.drag;
|
||||
|
||||
Reference in New Issue
Block a user