Fix groundDistance

This commit is contained in:
MrLetsplay 2022-11-14 09:33:01 +01:00
parent 69fd7af211
commit 459bf87869
3 changed files with 11 additions and 5 deletions

View File

@ -24,6 +24,8 @@ static ButtonElement *options;
static void defaultInput(GLFWwindow *window, void *data) { static void defaultInput(GLFWwindow *window, void *data) {
if(Input::isKeyboardCaptured()) return; if(Input::isKeyboardCaptured()) return;
// TODO: move input handling to controller class, add NoclipController
glm::vec3 direction = glm::vec3(0); glm::vec3 direction = glm::vec3(0);
if(Input::getKeyState(keyForward) == GLFW_PRESS) { if(Input::getKeyState(keyForward) == GLFW_PRESS) {
@ -52,6 +54,8 @@ static void defaultInput(GLFWwindow *window, void *data) {
direction += glm::vec3(0,-1,0); direction += glm::vec3(0,-1,0);
} }
kekData.player->controller->update();
direction = glm::normalize(direction); direction = glm::normalize(direction);
if(glm::length2(direction) > 0) { if(glm::length2(direction) > 0) {
if(kekData.player->noclip) { if(kekData.player->noclip) {
@ -68,8 +72,6 @@ static void defaultInput(GLFWwindow *window, void *data) {
if(jump) kekData.player->controller->jump(); if(jump) kekData.player->controller->jump();
} }
} }
kekData.player->controller->update();
} }
static void defaultKeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods, void *data) { static void defaultKeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods, void *data) {

View File

@ -30,10 +30,10 @@ static bool castPlayer(glm::vec3 pos, glm::vec3 delta, const btCollisionObject *
return true; return true;
} }
static bool checkPlayerGrounded() { bool DefaultPlayerController::checkPlayerGrounded() {
glm::vec3 point; glm::vec3 point;
glm::vec3 normal; glm::vec3 normal;
bool onGround = castPlayer(kekData.player->getPosition(), glm::vec3(0,-1,0), nullptr, nullptr, &point, &normal); bool onGround = castPlayer(kekData.player->getPosition(), glm::vec3(0,-groundDistance,0), nullptr, nullptr, &point, &normal);
// TODO: angle check // TODO: angle check
return onGround; return onGround;
} }
@ -79,7 +79,7 @@ glm::vec3 DefaultPlayerController::move(glm::vec3 movement) {
} }
void DefaultPlayerController::jump() { void DefaultPlayerController::jump() {
velocity += glm::vec3(0, 10 * jumpHeight, 0); velocity += glm::vec3(0, 10 * jumpHeight, 0) * kekData.lastFrameTime;
} }
void DefaultPlayerController::update() { void DefaultPlayerController::update() {

View File

@ -6,11 +6,15 @@ namespace kek {
class DefaultPlayerController: public PlayerController { class DefaultPlayerController: public PlayerController {
protected:
bool checkPlayerGrounded();
public: public:
glm::vec3 gravity = glm::vec3(0,-9.81,0); glm::vec3 gravity = glm::vec3(0,-9.81,0);
float minSlideAngle = 5; float minSlideAngle = 5;
float maxWalkAngle = 60; float maxWalkAngle = 60;
float jumpHeight = 1; float jumpHeight = 1;
float groundDistance = 0.01;
glm::vec3 velocity = glm::vec3(0); glm::vec3 velocity = glm::vec3(0);