From 55dc3dc9432e43220890414c61ef0dc0e38c107f Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Sat, 1 Apr 2023 22:35:16 -0700 Subject: [PATCH] Making Solid Controller work --- .../scene/components/physics/2d/CMakeLists.txt | 2 +- .../components/physics/2d/SolidController2D.cpp | 15 +++++++-------- .../components/physics/2d/TriggerController2D.hpp | 5 ++++- src/dawnrose/CMakeLists.txt | 3 ++- src/dawnrose/scenes/HelloWorldScene.hpp | 11 +++++++---- 5 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/dawn/scene/components/physics/2d/CMakeLists.txt b/src/dawn/scene/components/physics/2d/CMakeLists.txt index fed5bc57..6b89aa45 100644 --- a/src/dawn/scene/components/physics/2d/CMakeLists.txt +++ b/src/dawn/scene/components/physics/2d/CMakeLists.txt @@ -10,5 +10,5 @@ target_sources(${DAWN_TARGET_NAME} Collider2D.cpp CharacterController2D.cpp SolidController2D.cpp - TriggerCollider2D.cpp + TriggerController2D.cpp ) \ No newline at end of file diff --git a/src/dawn/scene/components/physics/2d/SolidController2D.cpp b/src/dawn/scene/components/physics/2d/SolidController2D.cpp index 5556f89d..1dca0682 100644 --- a/src/dawn/scene/components/physics/2d/SolidController2D.cpp +++ b/src/dawn/scene/components/physics/2d/SolidController2D.cpp @@ -29,22 +29,21 @@ bool_t SolidController2D::getCollidingResult( assertNotNull(movingObject); if(movement.x == 0 && movement.y == 0) return false; - auto localPos = this->transform->getLocalPosition(); + auto localPos = movingObject->transform->getWorldPosition(); glm::vec2 myPos(localPos.x, localPos.z); - - // Check what THIS is + // Check what the moving object is switch(movingObject->getColliderType()) { case COLLIDER2D_TYPE_BOX: { - auto box1 = dynamic_cast(this); + auto box1 = dynamic_cast(movingObject); assertNotNull(box1); - // Box VS ? - switch(collider->getColliderType()) { + // Box VS (this)? + switch(this->collider->getColliderType()) { case COLLIDER2D_TYPE_BOX: { - auto box2 = dynamic_cast(collider); + auto box2 = dynamic_cast(this->collider); assertNotNull(box2); - auto localPos2 = box2->transform->getLocalPosition(); + auto localPos2 = box2->transform->getWorldPosition(); glm::vec2 otherPos(localPos2.x, localPos2.z); return boxCheckCollision( diff --git a/src/dawn/scene/components/physics/2d/TriggerController2D.hpp b/src/dawn/scene/components/physics/2d/TriggerController2D.hpp index 90200e9e..00b14d97 100644 --- a/src/dawn/scene/components/physics/2d/TriggerController2D.hpp +++ b/src/dawn/scene/components/physics/2d/TriggerController2D.hpp @@ -5,8 +5,11 @@ #pragma once #include "Collider2D.hpp" +#include "BoxCollider.hpp" namespace Dawn { + class CharacterController2D; + class TriggerController2D : public SceneItemComponent { public: Collider2D *collider = nullptr; @@ -20,6 +23,6 @@ namespace Dawn { * Returns whether or not the given moving object is colliding with this * trigger collider. */ - bool_t getCollidingResult(Collider2D* movingObject) + bool_t getCollidingResult(Collider2D* movingObject); }; } \ No newline at end of file diff --git a/src/dawnrose/CMakeLists.txt b/src/dawnrose/CMakeLists.txt index 39725090..88e6ee5a 100644 --- a/src/dawnrose/CMakeLists.txt +++ b/src/dawnrose/CMakeLists.txt @@ -22,4 +22,5 @@ set(ROSE_ASSETS_DIR ${DAWN_ASSETS_DIR}/games/rose) tool_prefab(${ROSE_ASSETS_DIR}/prefabs/Player.xml) tool_prefab(${ROSE_ASSETS_DIR}/prefabs/Urchin.xml) tool_prefab(${ROSE_ASSETS_DIR}/prefabs/Crab.xml) -tool_prefab(${ROSE_ASSETS_DIR}/prefabs/SwordHitbox.xml) \ No newline at end of file +tool_prefab(${ROSE_ASSETS_DIR}/prefabs/SwordHitbox.xml) +tool_prefab(${ROSE_ASSETS_DIR}/prefabs/Wall.xml) \ No newline at end of file diff --git a/src/dawnrose/scenes/HelloWorldScene.hpp b/src/dawnrose/scenes/HelloWorldScene.hpp index c34432a7..f469571a 100644 --- a/src/dawnrose/scenes/HelloWorldScene.hpp +++ b/src/dawnrose/scenes/HelloWorldScene.hpp @@ -9,6 +9,7 @@ #include "prefabs/Player.hpp" #include "prefabs/Urchin.hpp" #include "prefabs/Crab.hpp" +#include "prefabs/Wall.hpp" #include "prefabs/ui/debug/FPSLabel.hpp" #include "display/mesh/CapsuleMesh.hpp" #include "display/mesh/CubeMesh.hpp" @@ -23,11 +24,13 @@ namespace Dawn { auto player = Player::create(this); - auto urchin = Urchin::create(this); - urchin->transform.setLocalPosition(glm::vec3(0, 0, -5)); + auto wall = Wall::create(this); - auto crab = Crab::create(this); - crab->transform.setLocalPosition(glm::vec3(3, 0, 0)); + // auto urchin = Urchin::create(this); + // urchin->transform.setLocalPosition(glm::vec3(0, 0, -5)); + + // auto crab = Crab::create(this); + // crab->transform.setLocalPosition(glm::vec3(3, 0, 0)); canvas = UICanvas::create(this);