diff --git a/src/character_actor.cpp b/src/character_actor.cpp index e22fb60..211e40b 100644 --- a/src/character_actor.cpp +++ b/src/character_actor.cpp @@ -34,9 +34,9 @@ void CharacterActor::_process(double delta_time) { GDGAMEONLY(); void CharacterActor::_physics_process(double delta_time) { GDGAMEONLY(); // accelerate towards velocity target Vector3 const new_velocity = this->get_velocity().move_toward(this->velocity_target, delta_time * CharacterActor::ACCELERATION); - // only apply velocity if not grounded - Vector3 const gravity{this->is_on_floor() ? Vector3() : Vector3{0.f, this->get_velocity().y - 9.8f, 0.f}}; - this->set_velocity(new_velocity + gravity); + Vector3 const gravity{Vector3{0.f, this->get_velocity().y - 9.8f, 0.f}}; + // apply either gravity or walking velocity depending on results + this->set_velocity(this->is_on_floor() ? new_velocity : this->get_velocity() + gravity); // update position this->move_and_slide(); }