mardi 19 décembre 2017

how do i make sure a boolean remains true while checking for collision

i am trying to let my character land on a platform in my own SDL2 based framework. currently it is not working due to, if i have more than one platform, which is default if i spawn one. the character will only stay on the last platform added. the rest it will slowly fall through while the grounded boolean switches from true to false.

here is my code:

void NHTVScene::EntitiesGrounded()
{
    std::vector<Entity*>::iterator it = platformVector.begin();
    while (it != platformVector.end()) {
        if (player->isColliding((*it))) {
        player->velocity = Vector2(0, 0);
        player->grounded = true;
    }
    else if (!player->isColliding((*it))) {
        player->grounded = false;
    }

    it++;
    }
}

this function is called every deltatime update.

i know that this code makes it so that with every platform that is not colliding that the boolean is getting set to true, but i think its weird that it doesn't do that on the newest entry, and i have no clue how to do this properly.

I hope this is enough information to give some insight to my problem. if not, please let me know and i'll supply more.

Aucun commentaire:

Enregistrer un commentaire