Improved collision logic, still not perfect since it updates before PlayerSystem.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user