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();
#if DAWN_DEBUG_BUILD
this->debugGrid();
// this->debugGrid();
this->debugOrigin();
this->debugHitboxes();
#endif

View File

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

View File

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