Hey guys, I've been working on a platformer game in java recently and have just finished with collision tracking,
I've gotten it to work, but it is still buggy and I was wondering if anybody knows of better methods of doing this.
So pretty much (only) when a collision is detected with the player and the solid object I run this 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
| public void collision(Object o){ if(o instanceof Solid){ if(x+24<((Solid) o).getX()){ if(!(hspeed<0)){ noright=true; hspeed=0; } } if(x-24>((Solid) o).getX()+((Solid) o).getWidth()){ if(!(hspeed>0)){ noleft=true; hspeed=0; } } if(y-24<((Solid) o).getY()){ if(!(noright || noleft)){ onGround = true; vspeed = 0; y = ((Solid) o).getY()-24; } } else if(y>((Solid) o).getY()){} if(!(noright || noleft)) vspeed = -vspeed; } } |
FYI I reset noright, noleft, and onGround every update.
So.. I hope someone can contribute, thanks
