Improve controls
This commit is contained in:
@@ -10,7 +10,7 @@ export class CollisionCuboid extends Component {
|
||||
colliding_y: 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();
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
|
||||
@@ -2,13 +2,15 @@ import { Component } from "$/common/ecs/mod.ts";
|
||||
import { KeyCode } from "$/client/input_manager.ts";
|
||||
|
||||
export class PlayerControls extends Component {
|
||||
move_speed: number = 5;
|
||||
move_speed = 4;
|
||||
jump_force = 6.7;
|
||||
|
||||
// Keys
|
||||
move_forward: KeyCode = "KeyW";
|
||||
move_backwards: KeyCode = "KeyS";
|
||||
move_left: KeyCode = "KeyA";
|
||||
move_right: KeyCode = "KeyD";
|
||||
sprint_key: KeyCode = "ShiftLeft";
|
||||
|
||||
hotbar_1: KeyCode = "Digit1";
|
||||
hotbar_2: KeyCode = "Digit2";
|
||||
|
||||
+1
-1
@@ -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:furnace", 1));
|
||||
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);
|
||||
|
||||
|
||||
@@ -53,13 +53,15 @@ export class PlayerControlsSystem extends System {
|
||||
const rightX = cos;
|
||||
const rightZ = -sin;
|
||||
|
||||
velocity.vx = (forwardX * input_z + rightX * input_x) * controls.move_speed;
|
||||
velocity.vz = (forwardZ * input_z + rightZ * input_x) * controls.move_speed;
|
||||
const speed_modifier = InputManager.is_key_down(controls.sprint_key) ? 1.75 : 1;
|
||||
|
||||
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);
|
||||
|
||||
if (InputManager.is_key_pressed("Space") && cuboid?.colliding_y === 1) {
|
||||
velocity.vy += controls.move_speed;
|
||||
if (InputManager.is_key_down("Space") && cuboid?.colliding_y === 1) {
|
||||
velocity.vy += controls.jump_force;
|
||||
}
|
||||
|
||||
if (InputManager.is_key_pressed(controls.open_inventory)) {
|
||||
@@ -79,7 +81,7 @@ export class PlayerControlsSystem extends System {
|
||||
}
|
||||
|
||||
camera.x = position.x;
|
||||
camera.y = position.y + 1.79;
|
||||
camera.y = position.y + 1.69;
|
||||
camera.z = position.z;
|
||||
|
||||
if (InputManager.is_mouse_grabbed()) {
|
||||
|
||||
Reference in New Issue
Block a user