I was with some collision problems in my game, but I don't want to look every physic collision again for some nearly finished game, it is actually playable, the problem is, there is a kind of a pushing force that makes the character goes through a bit of the wall, and then, if you got hit enough, you won't be able to move, I thought about doing
if (position + this power).intersects(wall)
Don't apply power;
But I think that I did something wrong there and could not correct it, and then, I tried something different:
if(char.intersects(wall)) //It will do only if the character is inside the wall
{
if(char.y < wall.y) //If the character is below the wall's top
char.y++; //It will go up
else if(char.y > wall.y - wall.height)//If the character is above the bottom of the wall
char.y--; // it will go down
}
As you can see there, the problem is: they are reflexive, if one of them is true, the other is always true too, and I can't think what I need to do to solve this problem
If it is below the wall top, it certainly is above the bottom
If it is above the wall bottom, it certainly is below the top
Then this creates a problem where it will always execute the two functions, tried solving the problem with else if, but the problem is when offsetting the character with ++ and -- is not enough, then the character becomes stuck to the wall, can someone show me the fail in my logic?
Aucun commentaire:
Enregistrer un commentaire