# Simple gravity in opengl

This topic is 5077 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I looked around articles but couldn't find anything related to simple gravity. I have my object, which is pretty much a quad, i am doing collision and gravity tests so i can impliment them into my game (for now, collision is a seperate thing) here's my quad, very simple..
void quadra()
{
glColor3ub(255, 255, 255);
glVertex3f(move2, move3, 0.0f);
glVertex3f(move1, move3, 0.0f);
glVertex3f(move1, move4, 0.0f);
glVertex3f(move2, move4, 0.0f);
glEnd();
}


the move1/2/3/4 just control my collision responses. My question is: How can i make my quad 'jump', with adjustable but simplistic gravity? Thanks ahead!

##### Share on other sites
x_t = x_0 + t*v_0 + a/2*t^2
v_t = v_0 + a*t

x_0 is the current position
v_0 is the current valocity
a is the acceleration
t is the change in time
x_t is the new position
v_t is the new valocity

##### Share on other sites
hah Mike, how would i use that in this situation tho? When the person presses space (my current jump key), do i just set the velocity?

##### Share on other sites
A simple but decent solution I used in writing 2D particle systems involved keeping track of 4 variables.

The X position
The Y position
The X velocity
The Y velocity

I'd then update positions something a little like...

XPos = XPos + XVel
YPos = YPos + YVel
XVel = XVel * Friction
YVel = (YVel * Friction) + Gravity

It shouldn't be too hard to apply to 3D. Friction is a number between 0 and 1 indicating how fast the object slows down (something between 0.95 and 0.99 is good) and Gravity is how fast it accelerates back towards the ground (something really low, like 0.01). Not the most accurate solution, but very easy to implement.

##### Share on other sites
Quote:
 Original post by JovanWhen the person presses space (my current jump key), do i just set the velocity?

yes

and the acceleration is the amount of gravity

##### Share on other sites
so in my case it should be a negative number? :P

##### Share on other sites
Quote:
 Original post by Jovanso in my case it should be a negative number? :P

the velocity should be the opposite of acceleration when the player jumps

the direction of the acceleration is game dependent

##### Share on other sites
Okay mike, but one small problem, its not doing anything :( i set the velocity and acceleration, but it wont do anything :(

##### Share on other sites
make a timer for the jumping

##### Share on other sites
This question has nothing to do with OpenGL. Moved.

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5
khawk
11

• 9
• 9
• 9
• 11
• 11
• ### Forum Statistics

• Total Topics
633679
• Total Posts
3013299
×