Hey Everyone,

I'm having problems with my collisions. Basically when i colliding against a wall i cant slide if i press another key..For example. if i press The left arrow key and i am on the wall, if i continue to hold this key and try to press the up arrow my player wont move upwards. I hope you know what i mean. I know its probably a really easy fix but i need help.

Here is my player update method:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| public void update() {
movePlayer(); int curCol = tileMap.getColTile((int) x); int curRow = tileMap.getRowTile((int) y);
double xDest = x += dx; double yDest = y += dy;
double tempX = x; double tempY = y;
collision(x, yDest); if (dy < 0) { if (topLeft || topRight) { dy = 0; tempY = curRow * tileMap.getTileSize() + height / 2; } else { tempY += dy; } } if (dy > 0) { if (bottomLeft || bottomRight) { dy = 0; tempY = (curRow + 1) * tileMap.getTileSize() - height / 2; } else { tempY += dy; } } dy = 0; collision(xDest, y); if (dx < 0) { if (topLeft || bottomLeft) { dx = 0; tempX = curCol * tileMap.getTileSize() + width / 2; } else { tempX += dx; } } if (dx > 0) { if (topRight || bottomRight) { dx = 0; tempX = (curCol + 1) * tileMap.getTileSize() - width / 2; } else { tempX += dx; } } dx = 0;
x = tempX; y = tempY;
tileMap.setX((int) (Game.WIDTH * Game.SCALE / 2 - x)); tileMap.setY((int) (Game.HEIGHT * Game.SCALE / 2 - y)); }
public void movePlayer() { if (left) { dx -= moveSpeed; } if (right) { dx += moveSpeed; } if (up) { dy -= moveSpeed; } if (down) { dy += moveSpeed; } } |

I might have an idea on how to do it. i think you could use something like

1 2 3
| if(dx != 0 && dy != 0){ } |

Please any help is much appreciated.

Thanks

- GlennBrann