vendredi 18 mai 2018

C++ game collision detection not colliding properly

I'm building a scroll 2D game using Raylib and I'm having a few issues colliding my player into objects properly. I'm successfully colliding the player into objects but instead of stopping when it hits the target, it goes over/walks over it. So when there's stairs instead of me wanting to jump up each step, it automatically walks up on each step, which is not what I want. The code snippet is below;

      for(int i =0; i < MAX_FLOOR;  i++){

       if(CheckCollisionRecs((Rectangle){player.x,player.y,player.width,player.height},(Rectangle){platforms[i].position.x, platforms[i].position.y, platforms[i].scale.x, platforms[i].scale.y})){

             // when collide put player on top of tiles/platforms
             player.y = platforms[i].position.y - 50;
             // when collide give player.x the last held position  
             player.x = player.x                                            
      }
   }

Is there a way I can have the player stop from going any further when colliding, and stop the player from walking up the steps, or walking up any object when it collides?

Aucun commentaire:

Enregistrer un commentaire