# Thread: platform game logic, problem

ok, I'm starting to feel stupid for all these questions I ask...

Anyways, I have a problem with my thinking, the problem being platform game logic stuff, like collision between the player and the platform.
Now, I have a rectangle collision type, called hgeRect. hgeRect has a function that checks intersection between two hgeRect. But the problem is that I can't check if the intersection is from top or bottom, or from the sides.
So, when the player is in air, and gets pulled down by the gravity, and lands on the platform, it stops, that isn't that hard, but the hard part is moving the player, 'cause no matter what method I use, I can't get it to do different things, depending on what side you hit the platform from, like, ofc the same action shouldn't be done, if the platfrom is hit from the bottom, or the top.

Sorry for my bad typing, or other flaws, I'm extremely tired :S

2. What the.. I thinl You a refreshment.
Code:
check if collided
check whether playerRect.y < platformRect.y
player is above the platform

3. It is usually best to check what is not inside of the collision rect than what is inside of it.

I cannot really help you much without a better description of what is happening. Yours was a bit vague which was probably because you were tired when you posted.

4. ok, I have an object, which collides with another object. Now, I want to be able to do different functions depending on where the objects collide, like, if it's the left side of one object and so on
I think audinue gave me the answer tho, Imma try that, thanks

5. 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?

6. Your logic for finding out the side seems a bit off, and where is 16 coming from? This is an imperfect method of attack however. To get it right all the time you will have to take into account the player's position before and after the fact. I've never written something like this, but I'm sure you could find code somewhere.

7. well, the + 16 finds the mid of the platform, since they're always 32x32 and the player x and y coordinates are fixed into being the mid of the character
So what it does for example if we take the left check, it checks if the player is left side of the platform, and then it also checks if the player is on the platform that way the player can move left and right, then he's on the platform, even tho he's on the left side of the platform, or right side :P

8. ok, I fixed this!
Here's the code if anyone will ever need it xP

Code:
void character::hitScreenBounds(){
//Hit right side
if( (x + 16) >= 1024 ) onLeft = true;
else onLeft = false;
//Hit left side
if( (x - 16) <= 0 ) onRight = true;
else onRight = false;
//Hit bottom
if( (y + 32) >= 768 ) onTop = true;
else onTop = false;
//Hit top
if( (y - 32) <= 0 ) onBottom = true;
else onBottom = false;

}
That did it