Testing some enemies
This commit is contained in:
@ -33,11 +33,7 @@ void CharacterController2D::onStart() {
|
||||
auto allColliders = getScene()->findComponents<Collider2D>();
|
||||
auto itColliders = allColliders.begin();
|
||||
|
||||
glm::vec2 normal;
|
||||
float_t entryTime;
|
||||
float_t exitTime;
|
||||
glm::vec2 entryPoint;
|
||||
glm::vec2 exitPoint;
|
||||
struct CharacterController2DCollisionEventInfo info;
|
||||
bool_t result = false;
|
||||
|
||||
// Check for collisions, definitely not working 100% yet
|
||||
@ -46,20 +42,33 @@ void CharacterController2D::onStart() {
|
||||
++itColliders;
|
||||
if(c == myCollider) continue;
|
||||
result = myCollider->getCollidingResult(
|
||||
velocity, c, normal, entryTime, exitTime, entryPoint, exitPoint
|
||||
) && entryTime <= delta;
|
||||
if(result) break;
|
||||
velocity,
|
||||
c,
|
||||
info.normal,
|
||||
info.entryTime,
|
||||
info.exitTime,
|
||||
info.entryPoint,
|
||||
info.exitPoint
|
||||
) && info.entryTime <= delta;
|
||||
if(result) {
|
||||
info.collider = c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(result) {
|
||||
moveAmount = glm::vec2(0, 0);
|
||||
velocity = glm::vec2(0, 0);
|
||||
this->eventCollision.invoke(info);
|
||||
} else {
|
||||
moveAmount = velocity;
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
|
@ -7,15 +7,23 @@
|
||||
#include "Collider2D.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
struct CharacterController2DCollisionEventInfo {
|
||||
Collider2D *collider;
|
||||
glm::vec2 normal;
|
||||
float_t entryTime;
|
||||
float_t exitTime;
|
||||
glm::vec2 entryPoint;
|
||||
glm::vec2 exitPoint;
|
||||
};
|
||||
|
||||
class CharacterController2D : public SceneItemComponent {
|
||||
private:
|
||||
void move(glm::vec2 distance);
|
||||
|
||||
public:
|
||||
// @optional
|
||||
glm::vec2 velocity = glm::vec2(0, 0);
|
||||
// @optional
|
||||
float_t friction = 12.0f;
|
||||
|
||||
StateEvent<struct CharacterController2DCollisionEventInfo> eventCollision;
|
||||
|
||||
CharacterController2D(SceneItem *i);
|
||||
void onStart() override;
|
||||
|
Reference in New Issue
Block a user