I guess I half ass fixed hitbox resolution

This commit is contained in:
2023-03-21 15:16:48 -07:00
parent 978c420046
commit 2bd6012297
4 changed files with 13 additions and 15 deletions

View File

@ -28,7 +28,7 @@ void Scene::update() {
this->itemsNotInitialized.clear(); this->itemsNotInitialized.clear();
#if DAWN_DEBUG_BUILD #if DAWN_DEBUG_BUILD
this->debugGrid(); // this->debugGrid();
this->debugOrigin(); this->debugOrigin();
this->debugHitboxes(); this->debugHitboxes();
#endif #endif

View File

@ -38,7 +38,7 @@ void CharacterController2D::onStart() {
float_t exitTime; float_t exitTime;
glm::vec2 entryPoint; glm::vec2 entryPoint;
glm::vec2 exitPoint; glm::vec2 exitPoint;
bool_t result; bool_t result = false;
// Check for collisions, definitely not working 100% yet // Check for collisions, definitely not working 100% yet
while(itColliders != allColliders.end()) { while(itColliders != allColliders.end()) {
@ -47,18 +47,13 @@ void CharacterController2D::onStart() {
if(c == myCollider) continue; if(c == myCollider) continue;
result = myCollider->getCollidingResult( result = myCollider->getCollidingResult(
velocity, c, normal, entryTime, exitTime, entryPoint, exitPoint velocity, c, normal, entryTime, exitTime, entryPoint, exitPoint
); ) && entryTime <= delta;
if(result) break; if(result) break;
} }
if(result && entryTime <= delta) { if(result) {
// Slide Resolution https://www.gamedev.net/articles/programming/general-and-gameplay-programming/swept-aabb-collision-detection-and-response-r3084/ moveAmount = glm::vec2(0, 0);
float dotprod = (velocity.x * normal.y) + (velocity.y * normal.x) * (1.0f - entryTime); velocity = glm::vec2(0, 0);
moveAmount = velocity * entryTime;
// Respond to changes
velocity.x = dotprod * normal.y;
velocity.y = dotprod * normal.x;
} else { } else {
moveAmount = velocity; moveAmount = velocity;
} }

View File

@ -22,7 +22,7 @@ bool_t Collider2D::getCollidingResult(
glm::vec2 &exitPoint glm::vec2 &exitPoint
) { ) {
assertNotNull(other); assertNotNull(other);
assertTrue(movement.x != 0 || movement.y != 0); if(movement.x == 0 && movement.y == 0) return false;
auto localPos = this->transform->getLocalPosition(); auto localPos = this->transform->getLocalPosition();
glm::vec2 myPos(localPos.x, localPos.z); glm::vec2 myPos(localPos.x, localPos.z);

View File

@ -27,11 +27,14 @@ namespace Dawn {
auto hitbox = playerItem->addComponent<BoxCollider>(); auto hitbox = playerItem->addComponent<BoxCollider>();
playerItem->addComponent<CharacterController2D>(); playerItem->addComponent<CharacterController2D>();
auto wallItem = this->createSceneItem(); auto wallBox = this->createSceneItem()->addComponent<BoxCollider>();
auto wallBox = wallItem->addComponent<BoxCollider>();
wallBox->min = glm::vec2(-4, -3); wallBox->min = glm::vec2(-4, -3);
wallBox->max = glm::vec2(-3, 3); wallBox->max = glm::vec2(-3, 3);
auto wallBox2 = this->createSceneItem()->addComponent<BoxCollider>();
wallBox2->min = glm::vec2(-3, -4);
wallBox2->max = glm::vec2(3, -3);
camera = Camera::create(this); camera = Camera::create(this);
camera->transform->lookAt(glm::vec3(10, 10, 10), glm::vec3(0, 0, 0)); camera->transform->lookAt(glm::vec3(10, 10, 10), glm::vec3(0, 0, 0));
// auto gameCamera = camera->item->addComponent<GameCamera>(); // auto gameCamera = camera->item->addComponent<GameCamera>();