This site requires JavaScript, please enable it in your browser!
Greenfoot back
CidalBlacksmoke
CidalBlacksmoke wrote ...

2013/6/20

Adding horizontal distance to jumping.

CidalBlacksmoke CidalBlacksmoke

2013/6/20

#
The main issue I'm having with my jumping is that my player cant land on the platforms I have made. When the player jumps they hit the edge of the platform and fall to the left and I'm not quite sure how to increase the distance the player jumps in the direction they are walking because the player jumps at the same speed that it walks.
Gevater_Tod4711 Gevater_Tod4711

2013/6/20

#
If your player jumps you change the y coordinate of this player. If you want to make him move while jumping you also have to change his x coordinate. But to help you with your certain code it would be helpfull to know the code you are using.
davmac davmac

2013/6/20

#
Usually you can make jumps go further by changing the initial vertical velocity (a higher jump will also go further) or reducing the vertical acceleration / gravity.
CidalBlacksmoke CidalBlacksmoke

2013/6/20

#
This is all the code involved in the jumping and falling process
 //ground code
 public void moveToGround(Actor ground)
    {
        int groundHeight = ground.getImage().getHeight();
        int newY = ground.getY() - (groundHeight + getImage().getHeight())/2;
        
        setLocation(getX(), newY);
        jumping = false;
    }
 //fall code
 public void checkFall()
  {
        if(onGround())
        {
            vSpeed =0;
        }
        else
        {
            fall();
        }
        
        
    }
 //jump code
  public void jump()
    {
        vSpeed = vSpeed - jumpStrength;
        jumping = true;
        fall();
    }
    //falling code
 public void fall()
    {setLocation(getX(), getY() +vSpeed);
     if(vSpeed <=9)
     {
        vSpeed = vSpeed + acceleration ;
    }
    jumping = true;
    }
    //makes ground solid
 public boolean onGround()
    {
        int spriteHeight = getImage().getHeight();
        int lookForGround = (int)(spriteHeight/2) + 5;
        
        Actor ground = getOneObjectAtOffset(0, lookForGround, floor.class);
        
        if(ground == null)
        {
            jumping = true;
            return false;
        }
        else
        {
            moveToGround(ground);
            return true;
        }
    }
Gevater_Tod4711 Gevater_Tod4711

2013/6/20

#
You probably call this methods from your act method. If you also call some methods for the movement in horizontall direction your character will move in both directions.
davmac davmac

2013/6/20

#
As I said before, increase the initial vertical velocity (jumpStrength) or decrease gravity (acceleration).
You need to login to post a reply.