diff --git a/src/dawn/scene/Scene.cpp b/src/dawn/scene/Scene.cpp index 86908e22..f097427a 100644 --- a/src/dawn/scene/Scene.cpp +++ b/src/dawn/scene/Scene.cpp @@ -28,7 +28,7 @@ void Scene::update() { this->itemsNotInitialized.clear(); #if DAWN_DEBUG_BUILD - this->debugGrid(); + // this->debugGrid(); this->debugOrigin(); this->debugHitboxes(); #endif diff --git a/src/dawn/scene/components/physics/2d/CharacterController2D.cpp b/src/dawn/scene/components/physics/2d/CharacterController2D.cpp index 2e1c12b6..fc252e30 100644 --- a/src/dawn/scene/components/physics/2d/CharacterController2D.cpp +++ b/src/dawn/scene/components/physics/2d/CharacterController2D.cpp @@ -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; } diff --git a/src/dawn/scene/components/physics/2d/Collider2D.cpp b/src/dawn/scene/components/physics/2d/Collider2D.cpp index 97d929b1..5b0c72e8 100644 --- a/src/dawn/scene/components/physics/2d/Collider2D.cpp +++ b/src/dawn/scene/components/physics/2d/Collider2D.cpp @@ -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); diff --git a/src/dawnrose/scenes/HelloWorldScene.hpp b/src/dawnrose/scenes/HelloWorldScene.hpp index a8230f4e..91e8b4e2 100644 --- a/src/dawnrose/scenes/HelloWorldScene.hpp +++ b/src/dawnrose/scenes/HelloWorldScene.hpp @@ -27,11 +27,14 @@ namespace Dawn { auto hitbox = playerItem->addComponent(); playerItem->addComponent(); - auto wallItem = this->createSceneItem(); - auto wallBox = wallItem->addComponent(); + auto wallBox = this->createSceneItem()->addComponent(); wallBox->min = glm::vec2(-4, -3); wallBox->max = glm::vec2(-3, 3); + auto wallBox2 = this->createSceneItem()->addComponent(); + wallBox2->min = glm::vec2(-3, -4); + wallBox2->max = glm::vec2(3, -3); + camera = Camera::create(this); camera->transform->lookAt(glm::vec3(10, 10, 10), glm::vec3(0, 0, 0)); // auto gameCamera = camera->item->addComponent();