I would like to know how to make my character move horizontally left or right bases on the a or s keys while he is in midair. I was thinking of using a method i already have for detecting if he is on a platform and if either the a or s key is pressed but it doesn't seem to be working. Am I on the right track?
public void fall()
{
setLocation ( getX(), getY() + vSpeed);
vSpeed = vSpeed + acceleration;
}
public boolean onGround()
{
Actor under = getOneObjectAtOffset ( 0, getImage().getHeight() / 2, Ground.class);
return under != null;
}
public void checkFall()
{
if(onGround())
{
vSpeed = 0;
}
else
{
fall();
}
}
public void jump()
{
if(Greenfoot.isKeyDown("space"))
{
vSpeed = -10;
fall();
}
if(under = null && (Greenfoot.isKeyDown("a")))
{
slide1();
}
if(under = null && (Greenfoot.isKeyDown("a")))
{
slide2();
}
}
public void slide1()
{
setLocation ( getX() + hSpeed, getY());
hSpeed = hSpeed;
}
public void slide2()
{
setLocation ( getX() + hSpeed, getY());
hSpeed = -hSpeed;
}

