Hello.
As Plattforms I use lines. the lines are horizontal at any given height.
----------
O
O : player
= : ground (also line)
- : plattform
Now I used to place a rectangle around the player and ask if the line intersects the rectangle, but this led to the player just touching the plattform and immediatly being placed on the plattform. even if he wanted to walk beneath it and it wasn’t very high.
So I tried telling him, to only place the player on the plattform if the Y-Axis value was the same as the Y-Axis value of the line.
Code:
`
Rectangle r3 = player.getBounds();
for (int j = 1; j<boxes.size(); j++) {
Line2D linie = (Line2D) boxes.get(j).makeLine2D();
if (r3.intersectsLine(linie) && player.getY()+player.getImage().getHeight(null) == linie.getY1() ) {
lineIntersected = true; //its a global boolean
player.setDy(0); //stop falling
player.setY(linie.getY1()-player.getImage().getHeight(null)); //place player on plattform
player.setCurrentY( (int) linie.getY1()); //this is just for animations, so it knows where to place them
} else if (!r3.intersectsLine(linie) && lineIntersected) {
lineIntersected = false;
player.setDy(-1); // move down (falling)
}
}`
This is part of my CheckCollision routine.
It’s total bullox and only works half ways if I delete the “else if”. Can anybody help me? Maybe you got a better idea how to make plattforms. they need to be placeable where I want them.
I’d be so very greatful