i have gravity code but when i run it the player does not stand at the bottom instead half the player is not shown and sometimes it falls through the platform an some help.
public class Player extends Actor
{
private int vSpeed = 0;
private int acceleration = 2;
private int speed = 5;
private int jumpStrength = 6;
public void act()
{
//calling on methods
move();
checkfall();
}
public void move()
{
if(Greenfoot.isKeyDown("left") || (Greenfoot.isKeyDown("a")))
{
move(-4);
setImage("Player-left.png");
}
if(Greenfoot.isKeyDown("right")|| (Greenfoot.isKeyDown("d")))
{
move(4);
setImage("Player-right.png");
}
if(Greenfoot.isKeyDown("space")|| (Greenfoot.isKeyDown("w")))
{
jump();
}
}
public void jump()
{
vSpeed = -jumpStrength;
fall();
}
public void checkfall()
{
if(onGround())
{
vSpeed = 0;
}else
{
fall();
}
}
public void fall()
{
setLocation(getX(), getY() + vSpeed);
vSpeed = vSpeed + acceleration;
}
public boolean onGround()
{
Actor under = getOneObjectAtOffset(0,getImage().getHeight()/2,Platform.class);
return under !=null;
}
