collisions remade

This commit is contained in:
viktorljung
2015-09-17 16:52:43 +02:00
parent 442554812d
commit c0155b7900
5 changed files with 18 additions and 14 deletions
+8 -7
View File
@@ -47,25 +47,26 @@ bool dd::Systems::BallSystem::Contact(const Events::Contact &event)
if (ballComponent1 != nullptr) {
ballEntity = event.Entity1;
otherEntitiy = event.Entity2;
//Make normal point from the other entity to the ball
normal = event.Normal * -1.f;
}
else if (ballComponent2 != nullptr) {
ballEntity = event.Entity2;
otherEntitiy = event.Entity1;
//Make normal point from the other entity to the ball
normal = event.Normal * 1.f;
}
else {
return false;
//TODO: Add support for power-up collisions
}
//normal.x = -normal.x;
auto ballTransform = m_World->GetComponent<Components::Transform>(ballEntity);
auto otherTransform = m_World->GetComponent<Components::Transform>(otherEntitiy);
glm::vec2 ballVelocity = glm::vec2(ballTransform->Velocity.x, ballTransform->Velocity.y);
glm::vec2 reflectedVelocity = ballVelocity - 2.f * glm::dot(ballVelocity, normal)*normal;
glm::vec2 reflectedVelocity = glm::reflect(ballVelocity, event.Normal);
ballTransform->Velocity = glm::vec3(reflectedVelocity, 0.f);
//LOG_INFO("Velocity: %f, %f\n", ballTransform->Velocity.x, ballTransform->Velocity.y);
return true;