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:
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 ;D