collisions remade
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user