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

Author Topic: Jump doesn't realistically  (Read 2967 times)

0 Members and 1 Guest are viewing this topic.

dotty

  • Jr. Member
  • **
  • Posts: 56
    • View Profile
Jump doesn't realistically
« on: January 20, 2012, 08:40:27 pm »
Hay I have a simple script which makes my sprite jump.

I have this line being fired every frame

Quote
   this->sprite.Move( (this->deltaTime * this->xVelocity), (this->jumpSpeed * this->deltaTime) * this->yVelocity);


And when my jump button is pressed this code gets run

Quote
this->yVelocity = -this->weight;
      if (this->sprite.GetPosition().y < apex) {
         this->isJumping = false;
      }


This works well. I hit jump, my character jumps, reaches a peak then drops down. However, my movement is more like an upside down V rather than an arch. How would I accomplish a more "real" jump effect?

Tex Killer

  • Full Member
  • ***
  • Posts: 242
    • View Profile
Jump doesn't realistically
« Reply #1 on: January 20, 2012, 08:46:14 pm »
Your yVelocity variable should be changed every frame to simulate gravity.

dotty

  • Jr. Member
  • **
  • Posts: 56
    • View Profile
Jump doesn't realistically
« Reply #2 on: January 21, 2012, 11:47:11 am »
How would I about doing this? If Y is above a certain point then change the yVelocity, or if a certin amount of time has pass changed the Yvelocity?

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Jump doesn't realistically
« Reply #3 on: January 21, 2012, 12:48:30 pm »
add some small amount to your y velocity every frame. When jumping add a far bigger (negative) amount to it.

Depending on your coordinate system, scale, etc. this might need some adjustments, so consider this just to give you an idea:
Code: [Select]
if(jump) dy -= 0.05;
dy += 0.001;

RedIrony

  • Newbie
  • *
  • Posts: 23
    • View Profile
Jump doesn't realistically
« Reply #4 on: January 21, 2012, 06:29:57 pm »
Kinda what Mario said, you have a position and a velocity, so why not add an acceleration (which is how you'd calculate the effect of gravity anyhow), so now it is:
Code: [Select]
velocity.y += acceleration.y; // acceleration.y would be negative, while velocity.y would initially be positive.
position.y += velocity.y;

TheEnigmist

  • Full Member
  • ***
  • Posts: 119
    • View Profile
Jump doesn't realistically
« Reply #5 on: January 23, 2012, 01:59:04 pm »
There is a problem with different frame.
I made something like in this topic gravity -= 0.1f; and move it, when stp jumping set again the gravity to old value.
The problem is if i enable VSync the sprite jump really high, if i disable it it jump like i want... how can i fix this?
I was thinking about using clock.getelapsedtipe().assecond() to make jumptimer the same!

Orwel

  • Full Member
  • ***
  • Posts: 208
    • View Profile
Jump doesn't realistically
« Reply #6 on: January 23, 2012, 03:34:51 pm »
this->yVelocity = -this->weight;  => this->yVelocity = -this->weight*delta_time;


Maybe  :roll: