Didn't wanna make a new topic for this, 'cause it feels like I'm spamming these boards :S
Anyways, I have this code:
Code:
bool character::platCollide(platform& p){
if(rect.Intersect(&p.rect)){
//check if left side
//I add it with 16 to make it the mid of the platform
if( (p.x + 16) > x && (p.y + 1) < y){
onLeft = true;
} else onLeft = false;
//check if right side
if( (p.x + 16) < x && (p.y + 1) < y){
onRight = true;
}else onRight = false;
//check if top
if( (p.y + 16) > y && (p.y + 1) > y){
onTop = true;
} else onTop = false;
//check if bottom
if( (p.y + 16) < y && (p.y + 31) < y){
onBottom = true;
}else onBottom = false;
return true;
}
return false;
}
Code:
void character::pullDown(){
if(!onTop)
y += gravityPull;
}
it works fine, but then when the player goes off the platforms again, like into the air, the gravity doesn't affect the player. Now this seems kinda obvious, 'cause I have no code telling it to do so, but it doesn't work to just do
Code:
if(!rect.Intersect(&p.rect)){
onTop = false;
onLeft = false;
onRight = false;
onBottom = false;
}
If I try to do this, the player just passes through the platforms, like no collision at all :S
Any ideas?
thanks in advance!