I am programming a aquarium and I'm having trouble with the movement of the fish. The plan was moving the fish with for loops to the random location set by random variables.
void EntityControl::movementController(std::vector<Fish*> * fishInputVector)
{
while (true) {
for (auto fish_ptr : *fishInputVector) {
//fix this
for (auto fish_ptr2 : *fishInputVector) {
//random location
unsigned int x = rand() % xContainer;
unsigned int y = rand() % yContainer;
unsigned int z = rand() % zContainer;
//if (!CheckCollision(fish_ptr, fish_ptr2)) {
unsigned int xPos = fish_ptr->getX();
unsigned int yPos = fish_ptr->getY();
unsigned int zPos = fish_ptr->getZ();
}
//}
}
}
}
this didn't work so I tried a lot of different things but I was not succesful in making it work. I also have a collision detector which detects when the fish are 1 x/y/z away from each other. Another action should be taken when this happens.
bool EntityControl::CheckCollision(Fish * fishInput, Fish * fishInput2)
{
//collision true/false
bool collision = false;
//collision detectors
bool xCollision = false;
bool yCollision = false;
bool zCollision = false;
//fishInput
unsigned int xOriginal = fishInput->getX();
unsigned int yOriginal = fishInput->getY();
unsigned int zOriginal = fishInput->getZ();
//fishInput2
unsigned int xEntity = fishInput2->getX();
unsigned int yEntity = fishInput2->getY();
unsigned int zEntity = fishInput2->getZ();
//directions, (triggerBox)
if (xOriginal - 1 == xEntity || xOriginal + 1 == xEntity || xOriginal == xEntity) { xCollision = true; }
if (yOriginal - 1 == yEntity || yOriginal + 1 == yEntity || yOriginal == yEntity) { yCollision = true; }
if (zOriginal - 1 == zEntity || zOriginal + 1 == zEntity || zOriginal == zEntity) { zCollision = true; }
//returns true if all 3 directions are true
if (xCollision && yCollision && zCollision) { collision = true; }
return collision;
}
Both are in the same class. I am looking more for a general direction than a solution. But both are fine.
problem summary Moving every fish in a random direction without static movement and calling the checkCollision constantly so it can check for collision.
Aucun commentaire:
Enregistrer un commentaire