bring back pre-0.30 player controls

This commit is contained in:
MihailRis 2026-03-22 22:21:40 +03:00
parent 0ddd8cff4f
commit 1d2c8cf4b6
4 changed files with 18 additions and 23 deletions

View file

@ -18,8 +18,8 @@ local function def_prop(name, def_value)
end
def_prop("jump_force", 0.0)
def_prop("air_damping", 1.0)
def_prop("ground_damping", 1.0)
def_prop("air_damping", 10.0)
def_prop("ground_damping", 10.0)
def_prop("movement_speed", 3.0)
def_prop("run_speed_mul", 1.5)
def_prop("crouch_speed_mul", 0.35)
@ -61,19 +61,10 @@ local function move_horizontal(speed, dir, vel)
if vec2.length(dir) > 0.0 then
vec2.normalize(dir, dir)
local magnitude = vec2.length({vel[1], vel[3]})
if magnitude <= 1e-4 or (magnitude < speed or vec2.dot(
{vel[1] / magnitude, vel[3] / magnitude}, dir) < 0.9)
then
vel[1] = vel[1] * 0.2 + dir[1] * speed * 0.8
vel[3] = vel[3] * 0.2 + dir[2] * speed * 0.8
end
magnitude = vec3.length({vel[1], 0, vel[3]})
if vec2.dot({vel[1] / magnitude, vel[3] / magnitude}, dir) > 0.5 then
vel[1] = vel[1] / magnitude * speed
vel[3] = vel[3] / magnitude * speed
end
local delta = time.delta()
local damping = body:get_linear_damping()
vel[1] = vel[1] + dir[1] * speed * delta * damping
vel[3] = vel[3] + dir[2] * speed * delta * damping
end
body:set_vel(vel)
end

View file

@ -107,7 +107,7 @@ glm::vec3 CameraControl::updateCameraShaking(
glm::vec3 offset {};
const float k = CAM_SHAKE_DELTA_K;
const float ov = CAM_SHAKE_OFFSET_Y;
const glm::vec3& vel = hitbox.velocity;
auto vel = hitbox.getSurfaceVelocity();
if (settings.shaking.get()) {
shake = shake * (1.0f - delta * k);
@ -252,7 +252,7 @@ void PlayerController::updateFootsteps(float delta) {
constexpr float GLM_PI = glm::pi<float>();
auto hitbox = player.getHitbox();
if (hitbox && hitbox->grounded) {
const glm::vec3& vel = hitbox->velocity;
glm::vec3 vel = hitbox->getSurfaceVelocity();
float f = glm::length(glm::vec2(vel.x, vel.z));
stepsTimer += delta * f * STEPS_SPEED;
if (stepsTimer >= GLM_PI) {

View file

@ -58,7 +58,6 @@ struct Hitbox {
glm::vec3 velocity;
glm::vec3 scale {1.0f, 1.0f, 1.0f};
float linearDamping = 0.5;
float friction = 1.0f;
float verticalDamping = 1.0f;
bool grounded = false;
float gravityScale = 1.0f;
@ -68,7 +67,10 @@ struct Hitbox {
float elasticity = 0.0f;
std::string material;
std::string groundMaterial;
// FIXME: only one must survive
glm::vec3 groundVelocity {};
glm::vec3 actualGroundVelocity {};
glm::vec3 prevPosition {};
glm::vec3 prevVelocity {};
@ -94,4 +96,8 @@ struct Hitbox {
prevPosition = vec;
}
}
glm::vec3 getSurfaceVelocity() const {
return velocity - actualGroundVelocity;
}
};

View file

@ -396,10 +396,11 @@ void PhysicsSolver::step(
}
for (auto hitbox : hitboxes) {
float linearDamping = hitbox->linearDamping * hitbox->friction;
float linearDamping = hitbox->linearDamping;
glm::vec3& vel = hitbox->velocity;
auto diff = hitbox->groundVelocity / dt - vel;
hitbox->actualGroundVelocity = hitbox->groundVelocity / dt;
auto diff = hitbox->actualGroundVelocity - vel;
vel.x += diff.x * delta * linearDamping;
vel.z += diff.z * delta * linearDamping;
@ -411,9 +412,6 @@ void PhysicsSolver::step(
}
updateSensors(*hitbox);
hitbox->friction = glm::abs(hitbox->gravityScale <= 1e-7f)
? 8.0f
: (!hitbox->prevGrounded ? 2.0f : 10.0f);
}
}