Improve controls

This commit is contained in:
2026-03-14 20:33:13 -03:00
parent d8dace3efa
commit 7e90f2ea57
4 changed files with 12 additions and 8 deletions
+1 -1
View File
@@ -10,7 +10,7 @@ export class CollisionCuboid extends Component {
colliding_y: number = 0; colliding_y: number = 0;
colliding_z: number = 0; colliding_z: number = 0;
constructor(width: number, height: number, depth: number, gravity = -9.8) { constructor(width: number, height: number, depth: number, gravity = -15.8) {
super(); super();
this.width = width; this.width = width;
this.height = height; this.height = height;
+3 -1
View File
@@ -2,13 +2,15 @@ import { Component } from "$/common/ecs/mod.ts";
import { KeyCode } from "$/client/input_manager.ts"; import { KeyCode } from "$/client/input_manager.ts";
export class PlayerControls extends Component { export class PlayerControls extends Component {
move_speed: number = 5; move_speed = 4;
jump_force = 6.7;
// Keys // Keys
move_forward: KeyCode = "KeyW"; move_forward: KeyCode = "KeyW";
move_backwards: KeyCode = "KeyS"; move_backwards: KeyCode = "KeyS";
move_left: KeyCode = "KeyA"; move_left: KeyCode = "KeyA";
move_right: KeyCode = "KeyD"; move_right: KeyCode = "KeyD";
sprint_key: KeyCode = "ShiftLeft";
hotbar_1: KeyCode = "Digit1"; hotbar_1: KeyCode = "Digit1";
hotbar_2: KeyCode = "Digit2"; hotbar_2: KeyCode = "Digit2";
+1 -1
View File
@@ -41,7 +41,7 @@ export function create_player(world: ClientWorld) {
// player_inventory.container.add_item(new ItemStack("bworld:carrot_seeds", 64)); // player_inventory.container.add_item(new ItemStack("bworld:carrot_seeds", 64));
player_inventory.container.add_item(new ItemStack("bworld:furnace", 1)); player_inventory.container.add_item(new ItemStack("bworld:furnace", 1));
player.add(new Camera()); player.add(new Camera());
player.add(new CollisionCuboid(0.5, 1.79, 0.5)); player.add(new CollisionCuboid(0.55, 1.79, 0.55));
world.add_entity(player); world.add_entity(player);
+7 -5
View File
@@ -53,13 +53,15 @@ export class PlayerControlsSystem extends System {
const rightX = cos; const rightX = cos;
const rightZ = -sin; const rightZ = -sin;
velocity.vx = (forwardX * input_z + rightX * input_x) * controls.move_speed; const speed_modifier = InputManager.is_key_down(controls.sprint_key) ? 1.75 : 1;
velocity.vz = (forwardZ * input_z + rightZ * input_x) * controls.move_speed;
velocity.vx = (forwardX * input_z + rightX * input_x) * controls.move_speed * speed_modifier;
velocity.vz = (forwardZ * input_z + rightZ * input_x) * controls.move_speed * speed_modifier;
const cuboid = player.get(CollisionCuboid); const cuboid = player.get(CollisionCuboid);
if (InputManager.is_key_pressed("Space") && cuboid?.colliding_y === 1) { if (InputManager.is_key_down("Space") && cuboid?.colliding_y === 1) {
velocity.vy += controls.move_speed; velocity.vy += controls.jump_force;
} }
if (InputManager.is_key_pressed(controls.open_inventory)) { if (InputManager.is_key_pressed(controls.open_inventory)) {
@@ -79,7 +81,7 @@ export class PlayerControlsSystem extends System {
} }
camera.x = position.x; camera.x = position.x;
camera.y = position.y + 1.79; camera.y = position.y + 1.69;
camera.z = position.z; camera.z = position.z;
if (InputManager.is_mouse_grabbed()) { if (InputManager.is_mouse_grabbed()) {