I followed the falling/ jumping tutorial I saw on youtube and I can't get my actor to just jump once (no double, triple, quadruple, etc.) and he keeps falling through the platforms that I have created. Anything stand out to you guys?
public class Giovanni extends Actor { private GreenfootImage giovanni_normal; private GreenfootImage giovanni_walk_right; private GreenfootImage giovanni_walk_right2; private GreenfootImage giovanni_walk_left; private GreenfootImage giovanni_walk_left2; private int speed = 2; //movement speed private int vSpeed = 0; //vertical speed private int acceleration = 2; //gravity effect while falling private int jumpStrength = -8; public Giovanni() { giovanni_normal = new GreenfootImage ("Stand.png"); giovanni_walk_right = new GreenfootImage ("Right.png"); giovanni_walk_right2 = new GreenfootImage ("Right2.png"); giovanni_walk_left = new GreenfootImage ("Left.png"); giovanni_walk_left2 = new GreenfootImage ("Left2.png"); } /** * Act - do whatever the Giovanni wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { move(); jump(); checkFall(); } public void move() { if (Greenfoot.isKeyDown("right")) { setLocation(getX()+speed,getY()); if(getImage() != giovanni_walk_right) { setImage(giovanni_walk_right); } else if (getImage() != giovanni_walk_right2) { setImage(giovanni_walk_right2); } } if (Greenfoot.isKeyDown("left")) { setLocation(getX()-speed,getY()); if(getImage() != giovanni_walk_left) { setImage(giovanni_walk_left); } else if (getImage() != giovanni_walk_right2) { setImage(giovanni_walk_left2); } } if (!Greenfoot.isKeyDown("right") && (!Greenfoot.isKeyDown("left"))) { setImage(giovanni_normal); } } public void jump() { if (Greenfoot.isKeyDown("space")) { vSpeed = jumpStrength; fall(); } } public void fall() { setLocation(getX(), getY()+vSpeed); vSpeed = vSpeed + acceleration; } public boolean onPlatform() { Actor under = getOneObjectAtOffset (0, getImage().getHeight()/2, Platform.class); return under != null; } public void checkFall() { if (onPlatform()) { vSpeed = 0; } else { fall(); } } }