physics-related fixes
This commit is contained in:
parent
47c6e35a0b
commit
997cff04d1
@ -35,9 +35,10 @@ Player::~Player() {
|
||||
}
|
||||
|
||||
void Player::updateInput(
|
||||
Level* level,
|
||||
PlayerInput& input,
|
||||
float delta) {
|
||||
Level* level,
|
||||
PlayerInput& input,
|
||||
float delta
|
||||
) {
|
||||
bool crouch = input.shift && hitbox->grounded && !input.sprint;
|
||||
float speed = this->speed;
|
||||
if (flight){
|
||||
@ -76,9 +77,9 @@ void Player::updateInput(
|
||||
hitbox->velocity.z += dir.z * speed * delta * 9;
|
||||
}
|
||||
|
||||
float vel = std::max(glm::length(hitbox->velocity * 0.25f), 1.0f);
|
||||
int substeps = int(delta * vel * 1000);
|
||||
substeps = std::min(100, std::max(1, substeps));
|
||||
float vel = glm::length(hitbox->velocity);
|
||||
int substeps = int(delta * vel * 20);
|
||||
substeps = std::min(100, std::max(2, substeps));
|
||||
level->physics->step(
|
||||
level->chunks.get(),
|
||||
hitbox.get(),
|
||||
|
||||
@ -21,16 +21,17 @@ void PhysicsSolver::step(
|
||||
float gravityScale,
|
||||
bool collisions
|
||||
) {
|
||||
float dt = delta / float(substeps);
|
||||
float dt = delta / static_cast<float>(substeps);
|
||||
float linear_damping = hitbox->linear_damping;
|
||||
float s = 2.0f/BLOCK_AABB_GRID;
|
||||
|
||||
const glm::vec3& half = hitbox->halfsize;
|
||||
glm::vec3& pos = hitbox->position;
|
||||
glm::vec3& vel = hitbox->velocity;
|
||||
|
||||
bool prevGrounded = hitbox->grounded;
|
||||
hitbox->grounded = false;
|
||||
for (uint i = 0; i < substeps; i++) {
|
||||
glm::vec3& pos = hitbox->position;
|
||||
glm::vec3& half = hitbox->halfsize;
|
||||
glm::vec3& vel = hitbox->velocity;
|
||||
float px = pos.x;
|
||||
float pz = pos.z;
|
||||
|
||||
@ -41,7 +42,8 @@ void PhysicsSolver::step(
|
||||
}
|
||||
vel.x *= glm::max(0.0f, 1.0f - dt * linear_damping);
|
||||
vel.z *= glm::max(0.0f, 1.0f - dt * linear_damping);
|
||||
pos += vel * dt;
|
||||
|
||||
pos += vel * dt + gravity * gravityScale * dt * dt * 0.5f;
|
||||
|
||||
if (shifting && hitbox->grounded){
|
||||
float y = (pos.y-half.y-E);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user