Update
Changed the collision code again and made a Component for AABB, now it seems that the problem is only on Horizontal collision, it doesn't push the object enought it think but is the same code as Y axis so it shouldn't be a problem.
(It do detects the horizontal Collision the resolution is the problem)
void Hermes_Player::Collision(GameObject * other)
{
if (other->GetTag() == "wall") {
AABB* myAABB = dynamic_cast<AABB*>(this->GetComponent("aabb"));
AABB* otherAABB = dynamic_cast<AABB*>(other->GetComponent("aabb"));
if (abs(myAABB->lastCenter.x - otherAABB->lastCenter.x) < myAABB->halfCenter.x + otherAABB->halfCenter.x) {
std::cout << "y" << std::endl;
if (myAABB->center.y < otherAABB->center.y) {
int distance = (myAABB->halfCenter.y + otherAABB->halfCenter.y) - (otherAABB->center.y - myAABB->center.y);
this->Position.y -= distance;
myAABB->center.y = (myAABB->center.y - distance);
}
if (myAABB->center.y > otherAABB->center.y) {
int distance = (myAABB->halfCenter.y + otherAABB->halfCenter.y) - (myAABB->center.y - otherAABB->center.y);
this->Position.y += distance;
myAABB->center.y = (myAABB->center.y + distance);
}
}
else
{
std::cout << "x" << std::endl;
int dist = myAABB->halfCenter.x + otherAABB->halfCenter.x;
int dif = (this->Size.x + other->Size.x) /2- abs(dist);
if (myAABB->center.x < otherAABB->center.x) {
int distance = (myAABB->halfCenter.x + otherAABB->halfCenter.x) - (otherAABB->center.x - myAABB->center.x);
this->Position.x -= distance;
myAABB->center.x = (myAABB->center.x - distance);
}
if (myAABB->center.x > otherAABB->center.x) {
int distance = (myAABB->halfCenter.x + otherAABB->halfCenter.x) - (myAABB->center.x - otherAABB->center.x);
this->Position.x += distance;
myAABB->center.x = (myAABB->center.x + distance);
}
std::cout << this->Position.x << std::endl;
}
}
}