Tweak gravity and jumping
This commit is contained in:
@@ -25,7 +25,11 @@ export abstract class Entity {
|
|||||||
width: number;
|
width: number;
|
||||||
height: number;
|
height: number;
|
||||||
eye_height: number;
|
eye_height: number;
|
||||||
gravity = -15.8;
|
// blocks per second squared
|
||||||
|
gravity = -32;
|
||||||
|
// 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;
|
||||||
|
|
||||||
// which way it hit something on each axis in the last move: 1 or -1, 0 for nothing.
|
// 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
|
// 1 on y means it's standing on something
|
||||||
@@ -70,11 +74,14 @@ export abstract class Entity {
|
|||||||
// one step of the game, TICK_DELTA seconds
|
// one step of the game, TICK_DELTA seconds
|
||||||
abstract tick(): void;
|
abstract tick(): void;
|
||||||
|
|
||||||
// falls and moves by its velocity for one tick, see move_body
|
// falls and moves by its velocity for one tick (see move_body), then slows down from drag
|
||||||
move() {
|
move() {
|
||||||
const collisions = move_body(this, this.gravity, (x, y, z) => this.level.has_collision(x, y, z));
|
const collisions = move_body(this, this.gravity, (x, y, z) => this.level.has_collision(x, y, z));
|
||||||
this.colliding_x = collisions.x;
|
this.colliding_x = collisions.x;
|
||||||
this.colliding_y = collisions.y;
|
this.colliding_y = collisions.y;
|
||||||
this.colliding_z = collisions.z;
|
this.colliding_z = collisions.z;
|
||||||
|
this.vx *= this.drag;
|
||||||
|
this.vy *= this.drag;
|
||||||
|
this.vz *= this.drag;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ export class LocalPlayer extends Player {
|
|||||||
inventories = new ClientInventories();
|
inventories = new ClientInventories();
|
||||||
|
|
||||||
move_speed = 4;
|
move_speed = 4;
|
||||||
jump_force = 6.7;
|
// blocks per second, peaks about 1.25 blocks up with the entity's gravity and drag
|
||||||
|
jump_force = 9.23;
|
||||||
|
|
||||||
#ticks_since_sent = 0;
|
#ticks_since_sent = 0;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user