Testing some enemies
This commit is contained in:
@ -28,7 +28,7 @@ void Scene::update() {
|
||||
this->itemsNotInitialized.clear();
|
||||
|
||||
#if DAWN_DEBUG_BUILD
|
||||
// this->debugGrid();
|
||||
this->debugGrid();
|
||||
this->debugOrigin();
|
||||
this->debugHitboxes();
|
||||
#endif
|
||||
|
@ -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;
|
||||
|
@ -62,11 +62,11 @@ void Scene::debugLine(struct SceneDebugLine line) {
|
||||
}
|
||||
|
||||
void Scene::debugRay(struct SceneDebugRay ray) {
|
||||
this->debugLine((struct SceneDebugLine){
|
||||
.v0 = ray.start,
|
||||
.v1 = ray.start + ray.direction,
|
||||
.color = ray.color
|
||||
});
|
||||
struct SceneDebugLine line;
|
||||
line.v0 = ray.start;
|
||||
line.v1 = ray.start + ray.direction;
|
||||
line.color = ray.color;
|
||||
this->debugLine(line);
|
||||
}
|
||||
|
||||
void Scene::debugCube(struct SceneDebugCube cube) {
|
||||
@ -154,12 +154,13 @@ void Scene::debugHitboxes() {
|
||||
switch(c->getColliderType()) {
|
||||
case COLLIDER3D_TYPE_CUBE:
|
||||
auto asCube = dynamic_cast<CubeCollider*>(c);
|
||||
this->debugCube((struct SceneDebugCube){
|
||||
.min = asCube->min,
|
||||
.max = asCube->max,
|
||||
.color = COLOR_BLUE,
|
||||
.transform = asCube->transform->getWorldTransform()
|
||||
});
|
||||
struct SceneDebugCube c2;
|
||||
c2.min = asCube->min;
|
||||
c2.max = asCube->max;
|
||||
c2.color = COLOR_BLUE;
|
||||
c2.transform = asCube->transform->getWorldTransform();
|
||||
|
||||
this->debugCube(c2);
|
||||
break;
|
||||
}
|
||||
++itColliders;
|
||||
|
Reference in New Issue
Block a user