Fix defaultplayercontroller
This commit is contained in:
parent
459bf87869
commit
f4cdc01ff3
@ -182,19 +182,12 @@ void init() {
|
||||
positions[1] = btVector3(0, KEK_PLAYER_HEIGHT / 2 + KEK_PLAYER_RADIUS, 0);
|
||||
float radii[2] = {KEK_PLAYER_RADIUS, KEK_PLAYER_RADIUS};
|
||||
btCollisionShape *shape = new btMultiSphereShape(positions, radii, 2);
|
||||
btRigidBody *body = new btRigidBody(KEK_PLAYER_MASS, nullptr, shape);
|
||||
btRigidBody *body = new btRigidBody(0, nullptr, shape);
|
||||
body->setCollisionFlags(body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
|
||||
body->setFriction(3);
|
||||
body->setActivationState(DISABLE_DEACTIVATION);
|
||||
kekData.physics->world->addRigidBody(body);
|
||||
|
||||
/*btCollisionShape *jumpShape = new btSphereShape(KEK_PLAYER_RADIUS / 2);
|
||||
btGhostObject *jumpCollider = new btGhostObject();
|
||||
jumpCollider->setCollisionShape(jumpShape);
|
||||
jumpCollider->setCollisionFlags(jumpCollider->getCollisionFlags() | btCollisionObject::CF_NO_CONTACT_RESPONSE);
|
||||
jumpCollider->setActivationState(DISABLE_DEACTIVATION);
|
||||
kekData.physics->world->addCollisionObject(jumpCollider);*/
|
||||
|
||||
btTransform from;
|
||||
from.setIdentity();
|
||||
from.setOrigin(btVector3(0,0,0));
|
||||
|
@ -62,11 +62,11 @@ glm::vec3 DefaultPlayerController::move(glm::vec3 movement) {
|
||||
|
||||
normal = glm::normalize(normal);
|
||||
|
||||
float angle = 90.0f - glm::angle(normal, glm::normalize(movement)) / M_PI * 90.0f;
|
||||
totalMovement += movement * frac;
|
||||
|
||||
float angle = 90.0f - glm::angle(normal, glm::normalize(movement)) / M_PI * 90.0f;
|
||||
if(angle < minSlideAngle) break;
|
||||
|
||||
totalMovement += movement * frac;
|
||||
totalMovement += normal * 0.001f;
|
||||
|
||||
glm::vec3 remainingProjected = glm::normalize(glm::cross(normal, glm::cross(movement, normal))) * glm::length(movement) * (1 - frac);
|
||||
@ -79,19 +79,20 @@ glm::vec3 DefaultPlayerController::move(glm::vec3 movement) {
|
||||
}
|
||||
|
||||
void DefaultPlayerController::jump() {
|
||||
velocity += glm::vec3(0, 10 * jumpHeight, 0) * kekData.lastFrameTime;
|
||||
velocity += glm::vec3(0, jumpVelocity, 0);
|
||||
}
|
||||
|
||||
void DefaultPlayerController::update() {
|
||||
bool onGround = checkPlayerGrounded();
|
||||
kekData.player->onGround = onGround;
|
||||
|
||||
move(velocity * kekData.lastFrameTime);
|
||||
|
||||
if(!onGround) {
|
||||
velocity += gravity * kekData.lastFrameTime;
|
||||
}else{
|
||||
velocity = glm::vec3(0);
|
||||
}
|
||||
|
||||
move(velocity);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -46,6 +46,3 @@
|
||||
#define KEK_PLAYER_HEIGHT 2
|
||||
#define KEK_PLAYER_RADIUS 0.5f
|
||||
#define KEK_PLAYER_EYE_OFFSET (KEK_PLAYER_HEIGHT / 2 - KEK_PLAYER_RADIUS)
|
||||
#define KEK_PLAYER_MASS 50
|
||||
#define KEK_PLAYER_WALK_VELOCITY 6.0f
|
||||
#define KEK_PLAYER_JUMP_VELOCITY 2.4f
|
||||
|
@ -13,7 +13,7 @@ public:
|
||||
glm::vec3 gravity = glm::vec3(0,-9.81,0);
|
||||
float minSlideAngle = 5;
|
||||
float maxWalkAngle = 60;
|
||||
float jumpHeight = 1;
|
||||
float jumpVelocity = 2.5;
|
||||
float groundDistance = 0.01;
|
||||
|
||||
glm::vec3 velocity = glm::vec3(0);
|
||||
|
@ -81,13 +81,13 @@ int main(int argc, char **argv) {
|
||||
test->moveTo(glm::vec3(0,5,0));
|
||||
scene->addObject(test);*/
|
||||
|
||||
/*Mesh *mesh2 = ObjParser::loadMesh("object/cube_colored/Cube.obj");
|
||||
Mesh *mesh2 = ObjParser::loadMesh("object/cube_colored/Cube.obj");
|
||||
GameObject *test3 = new GameObject();
|
||||
btCollisionShape *shape2 = new btBoxShape(btVector3(1,1,1));
|
||||
test3->addPhysics(shape2, 0, btCollisionObject::CF_STATIC_OBJECT);
|
||||
test3->addMesh(mesh2);
|
||||
test3->moveTo(glm::vec3(2, 1, 2));
|
||||
scene->addObject(test3);*/
|
||||
scene->addObject(test3);
|
||||
|
||||
/*for(int i = 0; i < 10; i++) {
|
||||
GameObject *test2 = new GameObject();
|
||||
|
Loading…
Reference in New Issue
Block a user