Made the hurt hazard work better.
This commit is contained in:
		@@ -6,6 +6,7 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
#include "Collider2D.hpp"
 | 
			
		||||
#include "physics/2d/Box.hpp"
 | 
			
		||||
#include "physics/2d/Physics2D.hpp"
 | 
			
		||||
 | 
			
		||||
namespace Dawn {
 | 
			
		||||
  class BoxCollider : public Collider2D {
 | 
			
		||||
 
 | 
			
		||||
@@ -16,10 +16,6 @@ void CharacterController2D::onStart() {
 | 
			
		||||
  useEvent([&](float_t delta){
 | 
			
		||||
    // Common variables
 | 
			
		||||
    auto myCollider = item->getComponent<Collider2D>();
 | 
			
		||||
    glm::vec2 currentPosition(
 | 
			
		||||
      this->transform->getLocalPosition().x,
 | 
			
		||||
      this->transform->getLocalPosition().z
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    // Friction
 | 
			
		||||
    velocity -= velocity * friction * delta;
 | 
			
		||||
@@ -40,7 +36,7 @@ void CharacterController2D::onStart() {
 | 
			
		||||
      while(itColliders != allColliders.end()) {
 | 
			
		||||
        auto c = *itColliders;
 | 
			
		||||
        ++itColliders;
 | 
			
		||||
        if(c->item == this->item) continue;
 | 
			
		||||
        if(c->item == this->item || c->transform->isChildOf(this->transform)) continue;
 | 
			
		||||
        result = c->getCollidingResult(
 | 
			
		||||
          velocity,
 | 
			
		||||
          myCollider,
 | 
			
		||||
@@ -66,10 +62,10 @@ void CharacterController2D::onStart() {
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if(
 | 
			
		||||
      mathAbs<float_t>(moveAmount.x) <= 0.001f &&
 | 
			
		||||
      mathAbs<float_t>(moveAmount.y) <= 0.001f
 | 
			
		||||
    ) return;
 | 
			
		||||
    // if(
 | 
			
		||||
    //   mathAbs<float_t>(moveAmount.x) <= 0.001f &&
 | 
			
		||||
    //   mathAbs<float_t>(moveAmount.y) <= 0.001f
 | 
			
		||||
    // ) return;
 | 
			
		||||
 | 
			
		||||
    transform->setLocalPosition(
 | 
			
		||||
      transform->getLocalPosition() + (glm::vec3(moveAmount.x, 0, moveAmount.y) * delta)
 | 
			
		||||
@@ -81,7 +77,7 @@ void CharacterController2D::onStart() {
 | 
			
		||||
    while(itTriggers != allTriggers.end()) {
 | 
			
		||||
      auto c = *itTriggers;
 | 
			
		||||
      ++itTriggers;
 | 
			
		||||
      if(c->item == this->item) continue;
 | 
			
		||||
      if(c->item == this->item || c->transform->isChildOf(this->transform)) continue;
 | 
			
		||||
      if(c->getCollidingResult(myCollider)) {
 | 
			
		||||
        c->eventTriggerEnter.invoke(this);
 | 
			
		||||
      }
 | 
			
		||||
 
 | 
			
		||||
@@ -29,8 +29,7 @@ bool_t SolidController2D::getCollidingResult(
 | 
			
		||||
  assertNotNull(movingObject);
 | 
			
		||||
  if(movement.x == 0 && movement.y == 0) return false;
 | 
			
		||||
 | 
			
		||||
  auto localPos = movingObject->transform->getWorldPosition();
 | 
			
		||||
  glm::vec2 myPos(localPos.x, localPos.z);
 | 
			
		||||
  auto myPos = physics3Dto2D(movingObject->transform->getWorldPosition());
 | 
			
		||||
 | 
			
		||||
  // Check what the moving object is
 | 
			
		||||
  switch(movingObject->getColliderType()) {
 | 
			
		||||
@@ -43,8 +42,7 @@ bool_t SolidController2D::getCollidingResult(
 | 
			
		||||
        case COLLIDER2D_TYPE_BOX: {
 | 
			
		||||
          auto box2 = dynamic_cast<BoxCollider*>(this->collider);
 | 
			
		||||
          assertNotNull(box2);
 | 
			
		||||
          auto localPos2 = box2->transform->getWorldPosition();
 | 
			
		||||
          glm::vec2 otherPos(localPos2.x, localPos2.z);
 | 
			
		||||
          auto otherPos = physics3Dto2D(box2->transform->getWorldPosition());
 | 
			
		||||
 | 
			
		||||
          return boxCheckCollision(
 | 
			
		||||
            myPos, box1->min, box1->max,
 | 
			
		||||
 
 | 
			
		||||
@@ -32,8 +32,8 @@ bool_t TriggerController2D::getCollidingResult(Collider2D* movingObject) {
 | 
			
		||||
          auto box2 = dynamic_cast<BoxCollider*>(collider);
 | 
			
		||||
          assertNotNull(box2);
 | 
			
		||||
          return boxIsBoxColliding(
 | 
			
		||||
            box1->transform->getWorldPosition(), box1->min, box1->max,
 | 
			
		||||
            box2->transform->getWorldPosition(), box2->min, box2->max
 | 
			
		||||
            physics3Dto2D(box1->transform->getWorldPosition()), box1->min, box1->max,
 | 
			
		||||
            physics3Dto2D(box2->transform->getWorldPosition()), box2->min, box2->max
 | 
			
		||||
          );
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
 
 | 
			
		||||
@@ -13,7 +13,6 @@ namespace Dawn {
 | 
			
		||||
  class TriggerController2D : public SceneItemComponent {
 | 
			
		||||
    public:
 | 
			
		||||
      Collider2D *collider = nullptr;
 | 
			
		||||
 | 
			
		||||
      StateEvent<CharacterController2D*> eventTriggerEnter;
 | 
			
		||||
 | 
			
		||||
      TriggerController2D(SceneItem *i);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user