Jump to content

  • Log In with Google      Sign In   
  • Create Account


Basic Jumping and Gravity Implementation


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 Endemoniada   Members   -  Reputation: 291

Like
0Likes
Like

Posted 12 April 2013 - 08:04 PM

Hi guys,

 

I'm still really not sure about how to implement jumping and gravity:

 

 

float3 position(0,0,0;
float3 velocity(0,0,0);
 
// this sums the forces
float3 sumForces()
{
float gravity=-4.0f;
return float3(0,gravity,0);
}
 
// this gets called every frame
void update(float dt)
{
// mass = 1 so acceleration = forces
float3 acceleration=sumForces();
 
position += velocity*dt;
velocity += acceleration*dt;
}
 
// this gets called when controller input changed
void onInput()
{
 if(button_pressed){
  // add jump but to what ?
  forces.y=10.0f;
 }
}

 

What do I do when the button is pressed for a jump ? I think I should add a positive y-value to the forces but where ? It has to go away after a second or two.

 

And my velocity y-value will continually decrease because of gravity so I have to clamp that to a lower limit, but what should that be ? Shouldn't my guy go faster and faster the deeper he falls ?

 

Thanks.


Edited by Endemoniada, 12 April 2013 - 11:02 PM.


Sponsor:

#2 apatriarca   Crossbones+   -  Reputation: 1611

Like
0Likes
Like

Posted 13 April 2013 - 06:04 AM

It probably depends on the effect you are trying to achieve. You may for example apply an impulsive force which directly change the current y velocity to some value. Or you may apply some vertical force for a limited time. What kind of game are you trying to make? Do you want the effect to be realistic? Do you want the game to be very reactive? 



#3 Endemoniada   Members   -  Reputation: 291

Like
0Likes
Like

Posted 13 April 2013 - 08:52 AM

Here is some more info: the game has a first person perspective and jumping is pretty important, it doesn't have to be realistic but should feel good. The player needs to be able to jump across distances that he wouldn't be able to get to without jumping. Pretty much what you see in your run of the mill shooter.

 

Thanks.

 



#4 apatriarca   Crossbones+   -  Reputation: 1611

Like
1Likes
Like

Posted 17 April 2013 - 08:53 AM

To simulate a "realistic" jump from a first person perspective it isn't enough to add some propelling force. You have to simulate the entire jumping movement. You somehow have to simulate the "crunching" movement used to accumulate energy for the jump. 



#5 HypnotiC   Members   -  Reputation: 112

Like
1Likes
Like

Posted 17 April 2013 - 09:47 AM

I don't quite understand why you were bothered...

 

1) when user hit jump button, you can simply give velocity a positive y value, and everything else remains the same. 

 

2) I think you don't need to clamp velocity.y, but need to check for position.y so if you hit ground then velocity.y should be set to zero.

 

Do I understand your question correctly or completely wrong?



#6 Bacterius   Crossbones+   -  Reputation: 8188

Like
1Likes
Like

Posted 23 April 2013 - 07:26 AM

I don't quite understand why you were bothered...

 

1) when user hit jump button, you can simply give velocity a positive y value, and everything else remains the same. 

 

2) I think you don't need to clamp velocity.y, but need to check for position.y so if you hit ground then velocity.y should be set to zero.

 

Do I understand your question correctly or completely wrong?

 

Yeah but that will give a cartoony "bump" effect, Mario platformer style. I don't think that is what OP is looking for if he is working on shooter.


The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

 

- Pessimal Algorithms and Simplexity Analysis





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS