fix: player flight linearDamping, add verticalDamping (bool)
This commit is contained in:
parent
3cafc39555
commit
f3201b7742
@ -248,7 +248,7 @@ void PlayerController::postUpdate(float delta, bool input, bool pause) {
|
||||
updateFootsteps(delta);
|
||||
updateCamera(delta, input);
|
||||
}
|
||||
player->postUpdate(this->input, delta);
|
||||
player->postUpdate();
|
||||
camControl.refresh();
|
||||
if (input) {
|
||||
updateInteraction();
|
||||
|
||||
@ -94,17 +94,20 @@ void Player::updateInput(PlayerInput& input, float delta) {
|
||||
dir = glm::normalize(dir);
|
||||
hitbox->velocity += dir * speed * delta * 9.0f;
|
||||
}
|
||||
}
|
||||
|
||||
void Player::postUpdate(PlayerInput& input, float delta) {
|
||||
auto hitbox = getHitbox();
|
||||
if (hitbox == nullptr) {
|
||||
return;
|
||||
hitbox->linearDamping = PLAYER_GROUND_DAMPING;
|
||||
hitbox->verticalDamping = flight;
|
||||
if (flight){
|
||||
hitbox->linearDamping = PLAYER_AIR_DAMPING;
|
||||
if (input.jump){
|
||||
hitbox->velocity.y += speed * delta * 9;
|
||||
}
|
||||
if (input.shift){
|
||||
hitbox->velocity.y -= speed * delta * 9;
|
||||
}
|
||||
}
|
||||
position = hitbox->position;
|
||||
|
||||
if (flight && hitbox->grounded) {
|
||||
flight = false;
|
||||
if (!hitbox->grounded) {
|
||||
hitbox->linearDamping = PLAYER_AIR_DAMPING;
|
||||
}
|
||||
|
||||
if (input.jump && hitbox->grounded){
|
||||
@ -121,25 +124,20 @@ void Player::postUpdate(PlayerInput& input, float delta) {
|
||||
if (input.noclip) {
|
||||
noclip = !noclip;
|
||||
}
|
||||
|
||||
hitbox->linearDamping = PLAYER_GROUND_DAMPING;
|
||||
if (flight){
|
||||
hitbox->linearDamping = PLAYER_AIR_DAMPING;
|
||||
hitbox->velocity.y *= 1.0f - delta * 9;
|
||||
if (input.jump){
|
||||
hitbox->velocity.y += speed * delta * 9;
|
||||
}
|
||||
if (input.shift){
|
||||
hitbox->velocity.y -= speed * delta * 9;
|
||||
}
|
||||
}
|
||||
if (!hitbox->grounded) {
|
||||
hitbox->linearDamping = PLAYER_AIR_DAMPING;
|
||||
}
|
||||
|
||||
input.noclip = false;
|
||||
input.flight = false;
|
||||
}
|
||||
|
||||
void Player::postUpdate() {
|
||||
auto hitbox = getHitbox();
|
||||
if (hitbox == nullptr) {
|
||||
return;
|
||||
}
|
||||
position = hitbox->position;
|
||||
|
||||
if (flight && hitbox->grounded) {
|
||||
flight = false;
|
||||
}
|
||||
if (spawnpoint.y <= 0.1) {
|
||||
attemptToFindSpawnpoint();
|
||||
}
|
||||
@ -293,4 +291,4 @@ void Player::convert(dynamic::Map* data, const ContentLUT* lut) {
|
||||
Inventory::convert(inventory.get(), lut);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -65,7 +65,7 @@ public:
|
||||
void teleport(glm::vec3 position);
|
||||
void updateEntity();
|
||||
void updateInput(PlayerInput& input, float delta);
|
||||
void postUpdate(PlayerInput& input, float delta);
|
||||
void postUpdate();
|
||||
|
||||
void attemptToFindSpawnpoint();
|
||||
|
||||
@ -104,4 +104,4 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
#endif // SRC_OBJECTS_PLAYER_HPP_
|
||||
#endif // SRC_OBJECTS_PLAYER_HPP_
|
||||
|
||||
@ -41,6 +41,7 @@ struct Hitbox {
|
||||
glm::vec3 halfsize;
|
||||
glm::vec3 velocity;
|
||||
float linearDamping;
|
||||
bool verticalDamping = false;
|
||||
bool grounded = false;
|
||||
|
||||
Hitbox(glm::vec3 position, glm::vec3 halfsize);
|
||||
|
||||
@ -47,6 +47,9 @@ void PhysicsSolver::step(
|
||||
(prevGrounded && gravityScale > 0.0f) ? 0.5f : 0.0f);
|
||||
}
|
||||
vel.x *= glm::max(0.0f, 1.0f - dt * linearDamping);
|
||||
if (hitbox->verticalDamping) {
|
||||
vel.y *= glm::max(0.0f, 1.0f - dt * linearDamping);
|
||||
}
|
||||
vel.z *= glm::max(0.0f, 1.0f - dt * linearDamping);
|
||||
|
||||
pos += vel * dt + gravity * gravityScale * dt * dt * 0.5f;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user