Making Solid Controller work

This commit is contained in:
2023-04-01 22:35:16 -07:00
parent 2ce629dc52
commit 55dc3dc943
5 changed files with 21 additions and 15 deletions

View File

@ -10,5 +10,5 @@ target_sources(${DAWN_TARGET_NAME}
Collider2D.cpp Collider2D.cpp
CharacterController2D.cpp CharacterController2D.cpp
SolidController2D.cpp SolidController2D.cpp
TriggerCollider2D.cpp TriggerController2D.cpp
) )

View File

@ -29,22 +29,21 @@ bool_t SolidController2D::getCollidingResult(
assertNotNull(movingObject); assertNotNull(movingObject);
if(movement.x == 0 && movement.y == 0) return false; 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); glm::vec2 myPos(localPos.x, localPos.z);
// Check what the moving object is
// Check what THIS is
switch(movingObject->getColliderType()) { switch(movingObject->getColliderType()) {
case COLLIDER2D_TYPE_BOX: { case COLLIDER2D_TYPE_BOX: {
auto box1 = dynamic_cast<BoxCollider*>(this); auto box1 = dynamic_cast<BoxCollider*>(movingObject);
assertNotNull(box1); assertNotNull(box1);
// Box VS ? // Box VS (this)?
switch(collider->getColliderType()) { switch(this->collider->getColliderType()) {
case COLLIDER2D_TYPE_BOX: { case COLLIDER2D_TYPE_BOX: {
auto box2 = dynamic_cast<BoxCollider*>(collider); auto box2 = dynamic_cast<BoxCollider*>(this->collider);
assertNotNull(box2); assertNotNull(box2);
auto localPos2 = box2->transform->getLocalPosition(); auto localPos2 = box2->transform->getWorldPosition();
glm::vec2 otherPos(localPos2.x, localPos2.z); glm::vec2 otherPos(localPos2.x, localPos2.z);
return boxCheckCollision( return boxCheckCollision(

View File

@ -5,8 +5,11 @@
#pragma once #pragma once
#include "Collider2D.hpp" #include "Collider2D.hpp"
#include "BoxCollider.hpp"
namespace Dawn { namespace Dawn {
class CharacterController2D;
class TriggerController2D : public SceneItemComponent { class TriggerController2D : public SceneItemComponent {
public: public:
Collider2D *collider = nullptr; Collider2D *collider = nullptr;
@ -20,6 +23,6 @@ namespace Dawn {
* Returns whether or not the given moving object is colliding with this * Returns whether or not the given moving object is colliding with this
* trigger collider. * trigger collider.
*/ */
bool_t getCollidingResult(Collider2D* movingObject) bool_t getCollidingResult(Collider2D* movingObject);
}; };
} }

View File

@ -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/Player.xml)
tool_prefab(${ROSE_ASSETS_DIR}/prefabs/Urchin.xml) tool_prefab(${ROSE_ASSETS_DIR}/prefabs/Urchin.xml)
tool_prefab(${ROSE_ASSETS_DIR}/prefabs/Crab.xml) tool_prefab(${ROSE_ASSETS_DIR}/prefabs/Crab.xml)
tool_prefab(${ROSE_ASSETS_DIR}/prefabs/SwordHitbox.xml) tool_prefab(${ROSE_ASSETS_DIR}/prefabs/SwordHitbox.xml)
tool_prefab(${ROSE_ASSETS_DIR}/prefabs/Wall.xml)

View File

@ -9,6 +9,7 @@
#include "prefabs/Player.hpp" #include "prefabs/Player.hpp"
#include "prefabs/Urchin.hpp" #include "prefabs/Urchin.hpp"
#include "prefabs/Crab.hpp" #include "prefabs/Crab.hpp"
#include "prefabs/Wall.hpp"
#include "prefabs/ui/debug/FPSLabel.hpp" #include "prefabs/ui/debug/FPSLabel.hpp"
#include "display/mesh/CapsuleMesh.hpp" #include "display/mesh/CapsuleMesh.hpp"
#include "display/mesh/CubeMesh.hpp" #include "display/mesh/CubeMesh.hpp"
@ -23,11 +24,13 @@ namespace Dawn {
auto player = Player::create(this); auto player = Player::create(this);
auto urchin = Urchin::create(this); auto wall = Wall::create(this);
urchin->transform.setLocalPosition(glm::vec3(0, 0, -5));
auto crab = Crab::create(this); // auto urchin = Urchin::create(this);
crab->transform.setLocalPosition(glm::vec3(3, 0, 0)); // 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); canvas = UICanvas::create(this);