it keeps going right through the platform. and everytime i run it, it also slowly moves to the left for some reason.
How Do i fix it?
int vSpeed = 0;
int accel = 0;
private int gravity;
public void act()
{
checkFalling();
fall();
gravity--;
setLocation(getX(), getY() - gravity);
checkForJump();
checkCollision();
if(Greenfoot.isKeyDown("left")) {
move(-3);
}
if(Greenfoot.isKeyDown("right")) {
move(3);
} // Add your action code here.
}
public void fall()
{
setLocation(getX(), getY() + vSpeed);
}
public void checkFalling()
{
if(!isTouching(Wide.class))
{
vSpeed++;
}
else
vSpeed = 0;
}
public void jump()
{
if(Greenfoot.isKeyDown("up"))
{
vSpeed = -10;
}
}
private void checkForJump()
{
if (Greenfoot.isKeyDown("up"))
{ gravity = 20; // this will make the character jump
}
}
public void checkCollision()
{
Actor Wide = getOneIntersectingObject(Wide.class);
if(Wide!=null)
{
int r = getRotation();
if(r == 0)
{
setLocation(getX() - 2, getY());
}
else if(r == 90)
{
setLocation(getX(), getY() - 2);
}
else if(r == 180)
{
setLocation(getX() + 2, getY());
}
else if(r == 270)
{
setLocation(getX(), getY() + 2);
}
}
}
}
