Improved collision logic, still not perfect since it updates before PlayerSystem.

This commit is contained in:
William Moberg
2015-12-16 16:34:27 +01:00
parent cf0ff9bfe5
commit 6d1cbd928e
3 changed files with 46 additions and 8 deletions
+9 -8
View File
@@ -4,15 +4,18 @@
void CollisionSystem::UpdateComponent(World * world, ComponentWrapper & cAABB, double dt)
{
//cAABB is any entity that should be collideable.
//TODO: Update CollisionSystem system after PlayerSystem.
//Right now, cAABB is a component attached to any entity that should be collideable.
AABB thisBox;
if (!Collision::GetEntityBox(world, cAABB, thisBox)) {
return;
}
//Here c should be an object that moves, currently only players.
//Press 'Z' to enable/disable collision.
if (zPress) {
return;
}
//Here, mover should be an object that moves, currently only players.
for (auto& mover : *world->GetComponents("Player")) {
if (cAABB.EntityID == mover.EntityID) {
continue;
@@ -21,13 +24,11 @@ void CollisionSystem::UpdateComponent(World * world, ComponentWrapper & cAABB, d
if (!Collision::GetEntityBox(world, mover.EntityID, otherBox)) {
continue;
}
if (Collision::AABBVsAABB(thisBox, otherBox)) {
glm::vec3 resolveTranslation;
if (Collision::AABBVsAABB(otherBox, thisBox, resolveTranslation)) {
ComponentWrapper& trans = world->GetComponent(mover.EntityID, "Transform");
//TODO: Move entity to correct position on collision instead of this. Special treatment if both are movers.
glm::vec3 newPos = trans["Position"];
float moveSpeed = 0.12f;
newPos += moveSpeed * glm::normalize(newPos - thisBox.Center());
trans["Position"] = newPos;
//TODO: Special treatment if both are movers.
trans["Position"] = (glm::vec3)trans["Position"] + resolveTranslation;
}
}
}