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