Hey guys that is how far I got with my collision, the problem is just that if i jump on a block from underneath it my charakter gets stuck some kind of in the block. Does anyone spot the mistake?
?
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
73
74
75
76
77
78
79
public class Rainer extends Objects
{
private int speed = 7;
private int vSpeed = 0;
private int acceleration = 1;
private int jumpPower = 10; //Variable negativ*
public void act()
{
move(4);
checkFall();
}
public void move(int moveRange)
{
int dx = 0, dy = 0;
if (Greenfoot.isKeyDown("right"))
{
dx++;
}
if (Greenfoot.isKeyDown("left"))
{
dx--;
}
if (Greenfoot.isKeyDown("space"))
{
dy = dy - 10;
}
for (int i = 0; i < moveRange; i++)
{
setLocation(getX() + dx, getY());
if (getOneIntersectingObject(Block.class) != null) setLocation(getX() - dx, getY());
setLocation(getX(), getY() + dy);
if (getOneIntersectingObject(Block.class) != null) setLocation(getX(), getY() + dy);
}
}
public void fall()
{
setLocation (getX(), getY() + vSpeed);
vSpeed = vSpeed + acceleration;
}
public boolean onGround()
{
Actor under = getOneIntersectingObject(Block.class);
return under != null;
}
public void checkFall()
{
if(onGround())
{
vSpeed = 0;
}
else
{
fall();
}
}
public void jump()
{
vSpeed = -jumpPower;
fall();
}
}
