I need help figuring out how to tell if my actor hit the bottom of the Ground Class as well as the sides. I'd appreciate some help!
public class character extends Actor
{
public double vSpeed = 0;
public double acc = .6;
public int jumps = -15;
public int Left = -4;
public int Right = 4;
public void isFalling()
{
if(onGround() == false)
{
Gravity();
}
if(onTop() == true)
{
vSpeed += (-1*vSpeed + 4);
}
if(onGround() == true)
{
vSpeed = 0;
}
}
public void Jump()
{
if(Greenfoot.isKeyDown("Up") && onGround() == true)
{
vSpeed = jumps;
Gravity();
}
}
public void Gravity()
{
setLocation(getX(),getY() + (int)vSpeed);
vSpeed += acc;
}
public void moving()
{
if(Greenfoot.isKeyDown("Right"))
{
if(onGround() == false)
{
move(Right);
}
else
{
move(Right);
}
}
if(Greenfoot.isKeyDown("Left"))
{
if(onGround() == false)
{
move(Left);
}
else
{
move(Left);
}
}
}
public boolean onGround()
{
Actor under = getOneObjectAtOffset(0,getImage().getHeight()/2,Ground.class);
return under != null;
}
public boolean onLeft()
{
Actor isLeft = getOneObjectAtOffset(0,getImage().getWidth()/2,Ground.class);
return isLeft != null;
}
public boolean onRight()
{
Actor isRight = getOneObjectAtOffset(0,getImage().getWidth()*2,Ground.class);
return isRight != null;
}
public boolean onTop()
{
Actor isTop = getOneObjectAtOffset(0,getImage().getHeight()*2,Ground.class);
return isTop != null;
}
public void act()
{
Jump();
moving();
isFalling();
}
}
![Twitter](/assets/twitter-4e19209ef84344ee0c433f4c7bad8d49.png)
![Twitter.hover](/assets/twitter.hover-1fb19a5bafc50deace8f88eaec867845.png)