Thread: Intersection/gravity problem - Weird as hell

1. Member
Join Date
Apr 2013
Posts
2
Rep Power
0

Intersection/gravity problem - Weird as hell

Okay, so I have this code of my intersection and this checks for the intersection of the left, right and bottom sides of the player.
What is happening is:
My player falls a little bit, hits the ground and stops, then I walk to the left, it works fine, he stops when he hits the wall, but when I walk to the right side, he hits the wall, stops walking to the right, but suddenly starts sinking through the ground as if there was no ground.
Here's the all the code that has something to do with the movement(I haven't worked on intersectTop yet, since I can't get the others to work, that is the reason it is blank):
Java Code:
```public void loop() {
move();
gravitate();
}

public boolean intersectRight() {
for (int x = 0; x < xTiles; x++) {
for (int y = 0; y < yTiles; y++) {
if (player.intersects(blocks[x][y]) && blocks[x][y].solid) {
if (player.x + player.width >= blocks[x][y].x
&& player.x + player.width < blocks[x][y].x
+ (blockSize / 4)
&& player.y + player.height - (blockSize / 2) > blocks[x][y].y) {
player.x = blocks[x][y].x - blockSize;
System.out.println("Right: true");
return true;
}
}
}
}
return false;
}

public boolean intersectLeft() {
for (int x = 0; x < xTiles; x++) {
for (int y = 0; y < yTiles; y++) {
if (player.intersects(blocks[x][y]) && blocks[x][y].solid) {
if (player.x <= blocks[x][y].x + blockSize
&& player.x > blocks[x][y].x + (blockSize / 4)
&& player.y + player.height - (blockSize / 2) > blocks[x][y].y) {
player.x = blocks[x][y].x + blockSize;
System.out.println("Left: true");
return true;
}
}
}
}
return false;
}

public boolean intersectBot() {
for (int x = 0; x < xTiles; x++) {
for (int y = 0; y < yTiles; y++) {
if (player.intersects(blocks[x][y]) && blocks[x][y].solid) {
if (!intersectLeft() && !intersectRight()) {
if (player.y + player.height >= blocks[x][y].y) {

player.y = player.y
- (player.y + (player.height) - blocks[x][y].y);
}
return true;
}
}
}
}
return false;
}

public boolean intersectTop() {

return false;
}

public void move() {
player.x += player.dx;
player.y += player.dy;
}

public void gravitate() {
if (!intersectBot()) {
player.dy += (grav * gravMultiplier);
if (player.dy > 15) {
player.dy = 15;
}
} else {
player.dy = 0;
}
}```
Last edited by Mutt; 04-21-2013 at 02:40 PM. Reason: Adding some info

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•