Can walk up "stair-steps". Cleanup WIP.

Better performance in RectanglevsTriangle check.
Added IsOnGround flag and VerticalStepHeight in Physics.
Lotsa commented code saved for historical reasons, remove later.
This commit is contained in:
William Moberg
2016-02-05 10:56:34 +01:00
parent c4fb604617
commit d61e605093
6 changed files with 221 additions and 61 deletions
+11 -7
View File
@@ -50,11 +50,13 @@ void PlayerMovementSystem::Update(double dt)
wishSpeed = playerMovementSpeed;
}
glm::vec3& velocity = cPhysics["Velocity"];
ImGui::Text("velocity: (%f, %f, %f)", velocity.x, velocity.y, velocity.z);
bool isOnGround = (bool)cPhysics["IsOnGround"];
ImGui::Text(isOnGround ? "On ground" : "In air");
ImGui::Text("velocity: (%f, %f, %f) |%f|", velocity.x, velocity.y, velocity.z, glm::length(velocity));
glm::vec3 groundVelocity(0.f, 0.f, 0.f);
groundVelocity.x = glm::dot(velocity, glm::vec3(1.f, 0.f, 0.f));
groundVelocity.z = glm::dot(velocity, glm::vec3(0.f, 0.f, 1.f));
ImGui::Text("groundVelocity: (%f, %f, %f) |%f|", groundVelocity.x, groundVelocity.y, groundVelocity.z, glm::length(wishDirection));
groundVelocity.x = velocity.x;
groundVelocity.z = velocity.z;
ImGui::Text("groundVelocity: (%f, %f, %f) |%f|", groundVelocity.x, groundVelocity.y, groundVelocity.z, glm::length(groundVelocity));
ImGui::Text("wishDirection: (%f, %f, %f) |%f|", wishDirection.x, wishDirection.y, wishDirection.z, glm::length(wishDirection));
float currentSpeedProj = glm::dot(groundVelocity, wishDirection);
float addSpeed = wishSpeed - currentSpeedProj;
@@ -67,7 +69,7 @@ void PlayerMovementSystem::Update(double dt)
ImGui::InputFloat("accel", &accel);
static float airAccel = 0.5f;
ImGui::InputFloat("airAccel", &airAccel);
float actualAccel = (velocity.y != 0) ? airAccel : accel;
float actualAccel = isOnGround ? accel : airAccel;
static float surfaceFriction = 5.f;
ImGui::InputFloat("surfaceFriction", &surfaceFriction);
float accelerationSpeed = actualAccel * (float)dt * wishSpeed * surfaceFriction;
@@ -76,7 +78,8 @@ void PlayerMovementSystem::Update(double dt)
ImGui::Text("velocity: (%f, %f, %f) |%f|", velocity.x, velocity.y, velocity.z, glm::length(velocity));
}
if (controller->Jumping() && !controller->Crouching() && velocity.y == 0.f) {
if (controller->Jumping() && !controller->Crouching() && isOnGround) {
(bool)cPhysics["IsOnGround"] = false;
velocity.y += 4.f;
}
@@ -128,6 +131,7 @@ void PlayerMovementSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapp
ComponentWrapper& cPhysics = entity["Physics"];
glm::vec3& velocity = cPhysics["Velocity"];
bool isOnGround = (bool)cPhysics["IsOnGround"];
// Ground friction
float speed = glm::length(velocity);
@@ -135,7 +139,7 @@ void PlayerMovementSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapp
ImGui::InputFloat("groundFriction", &groundFriction);
static float airFriction = 0.f;
ImGui::InputFloat("airFriction", &airFriction);
float friction = (velocity.y != 0) ? airFriction : groundFriction;
float friction = isOnGround ? groundFriction : airFriction;
if (speed > 0) {
float drop = speed * friction * (float)dt;
float multiplier = glm::max(speed - drop, 0.f) / speed;