Implement walk angle, Fix slide angle
This commit is contained in:
parent
f4cdc01ff3
commit
64745491aa
@ -31,11 +31,19 @@ static bool castPlayer(glm::vec3 pos, glm::vec3 delta, const btCollisionObject *
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool DefaultPlayerController::checkPlayerGrounded() {
|
bool DefaultPlayerController::checkPlayerGrounded() {
|
||||||
|
glm::vec3 groundDir = glm::vec3(0,-groundDistance,0);
|
||||||
|
|
||||||
glm::vec3 point;
|
glm::vec3 point;
|
||||||
glm::vec3 normal;
|
glm::vec3 normal;
|
||||||
bool onGround = castPlayer(kekData.player->getPosition(), glm::vec3(0,-groundDistance,0), nullptr, nullptr, &point, &normal);
|
bool onGround = castPlayer(kekData.player->getPosition(), groundDir, nullptr, nullptr, &point, &normal);
|
||||||
// TODO: angle check
|
if(!onGround) return false;
|
||||||
return onGround;
|
|
||||||
|
normal = glm::normalize(normal);
|
||||||
|
|
||||||
|
float angle = 180.0f - glm::angle(normal, glm::normalize(groundDir)) / M_PI * 180.0f;
|
||||||
|
if(angle > maxWalkAngle) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
DefaultPlayerController::DefaultPlayerController() {
|
DefaultPlayerController::DefaultPlayerController() {
|
||||||
@ -64,7 +72,7 @@ glm::vec3 DefaultPlayerController::move(glm::vec3 movement) {
|
|||||||
|
|
||||||
totalMovement += movement * frac;
|
totalMovement += movement * frac;
|
||||||
|
|
||||||
float angle = 90.0f - glm::angle(normal, glm::normalize(movement)) / M_PI * 90.0f;
|
float angle = 180.0f - glm::angle(normal, glm::normalize(movement)) / M_PI * 180.0f;
|
||||||
if(angle < minSlideAngle) break;
|
if(angle < minSlideAngle) break;
|
||||||
|
|
||||||
totalMovement += normal * 0.001f;
|
totalMovement += normal * 0.001f;
|
||||||
|
@ -69,7 +69,7 @@ int main(int argc, char **argv) {
|
|||||||
btCollisionShape *shape = new btBoxShape(btVector3(0.5,5,25));
|
btCollisionShape *shape = new btBoxShape(btVector3(0.5,5,25));
|
||||||
wall->addPhysics(shape, 0, btCollisionObject::CF_STATIC_OBJECT);
|
wall->addPhysics(shape, 0, btCollisionObject::CF_STATIC_OBJECT);
|
||||||
wall->moveTo(glm::vec3(0,2.5,0));
|
wall->moveTo(glm::vec3(0,2.5,0));
|
||||||
wall->rotate(45.0f, glm::vec3(0,0,1));
|
wall->rotate(M_PI / 4, glm::vec3(0,0,1));
|
||||||
scene->addObject(wall);
|
scene->addObject(wall);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user