Skip to content

Commit

Permalink
character controls & fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Qendolin committed Jun 16, 2024
1 parent 7a62503 commit 3047ac6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
5 changes: 5 additions & 0 deletions src/Controller/RaceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ void RaceManager::onCheckpointEntered(CheckpointEntity *checkpoint) {
int index = indexOf(checkpoints_, checkpoint);
LOG_DEBUG("Entered checkpoint '" + std::to_string(index) + "'");

if (!character_->canEnterCheckpoints()) {
LOG_DEBUG("Character cannot enter checkpoints right now");
return;
}

if (ended_) {
return;
}
Expand Down
10 changes: 5 additions & 5 deletions src/Scene/Character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,32 +243,32 @@ glm::vec3 CharacterEntity::calculateVelocity_(float time_delta) {
}

// Looking straight ahead cancles 75% of gravity due to aerodynamic drag
float down_accel = -0.75f * GRAVITY_ACCELERATION;
float down_accel = -0.6f * GRAVITY_ACCELERATION;
result.y += down_accel * time_delta;

// Looking straight up or down would divide by zero
pitch_cos = glm::max(pitch_cos, glm::epsilon<float>());
// convert vertical to horizontal velocity
if (velocity.y < 0) {
float lift = velocity.y * -0.2f * pitch_cos_sqr * time_delta * SPEED;
float lift = velocity.y * -0.175f * pitch_cos_sqr * time_delta * SPEED;
result.y += lift;
result.x += looking.x * lift / pitch_cos;
result.z += looking.z * lift / pitch_cos;
}
// convert horizontal to vertical upwards velocity
// allows for flying up
if (camera.angles.x > 0) {
float lift = horizontal_speed * pitch_sin * 0.2f * time_delta * SPEED;
float lift = horizontal_speed * pitch_sin * 0.175f * time_delta * SPEED;
// Unrealistic but makes gaining hight easier.
// One problem is that this allows for infinite height gain.
// One problem is that this allows for infinite height gain when te factor is above 1.
result.y += lift * 1.0f;
result.x -= looking.x * lift / pitch_cos;
result.z -= looking.z * lift / pitch_cos;
}
// convert horizontal to vertical downwards velocity
// allows for better height control
if (camera.angles.x < 0) {
float anti_lift = horizontal_speed * pitch_sin_sqr * -0.1f * time_delta * SPEED;
float anti_lift = horizontal_speed * pitch_sin_sqr * -0.175f * 0.5f * time_delta * SPEED;
result.y += anti_lift;
result.x += looking.x * anti_lift / pitch_cos;
result.z += looking.z * anti_lift / pitch_cos;
Expand Down
4 changes: 4 additions & 0 deletions src/Scene/Character.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,8 @@ class CharacterEntity : public scene::NodeEntity {
JPH::BodyID body() const;

JPH::BodyID kinematicBody() const;

bool canEnterCheckpoints() const {
return respawnFreeze.isZero();
}
};
4 changes: 2 additions & 2 deletions src/Util/Timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ struct Timer {
if (value_ < 0) value_ = 0;
}

float value() {
float value() const {
return value_;
}

bool isZero() {
bool isZero() const {
return value_ == 0.0;
}

Expand Down

0 comments on commit 3047ac6

Please sign in to comment.