Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Help with Auto Jumping  (Read 1081 times)

0 Members and 1 Guest are viewing this topic.

Mesiow

  • Newbie
  • *
  • Posts: 1
    • View Profile
Help with Auto Jumping
« on: January 28, 2018, 04:25:51 am »
This is my first sfml project and I am attempting to make a doodle jump clone but I can't figure out how to make the sprite automatically jump. It just stops in the air after one jump. Any help would be appreciated


This is what my jumping function looks like



void Doodle::Jump(sf::RenderWindow &window)
{
     if(getSpritePos().y > window.getPosition().y)
      {
        mSprite.move(mVelocity);
      }

     if(getSprite().getGlobalBounds().intersects(mBottom.getGlobalBounds()))
      {
          mVelocity.y-=mGravity.y*acceleration.y;
          mSprite.move(mVelocity);

      }

      if(mVelocity.y<=0)
      {
          mVelocity.y=-5.0f;
      }

}


 

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11016
    • View Profile
    • development blog
    • Email
Re: Help with Auto Jumping
« Reply #1 on: January 28, 2018, 11:26:40 am »
Looks to me like you're only adjusting the velocity when something happens (collision etc), but gravity pulls on your character even if they're not colliding.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/