But how would you end up doing gravity? just add a constant loop to y -0.1 or some other value to simulate gravity?? I know gravity is way more complex than that though...
g = 9.8 m/s2 = 32.2 ft/s2 thats the earth's gravity...
OpenGL easier than I thought
Moderator: Coders of Rage
- davidthefat
- Chaos Rift Maniac
- Posts: 529
- Joined: Mon Nov 10, 2008 3:51 pm
- Current Project: Fully Autonomous Robot
- Favorite Gaming Platforms: PS3
- Programming Language of Choice: C++
- Location: California
- Contact:
- dandymcgee
- ES Beta Backer
- Posts: 4709
- Joined: Tue Apr 29, 2008 3:24 pm
- Current Project: https://github.com/dbechrd/RicoTech
- Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
- Programming Language of Choice: C
- Location: San Francisco
- Contact:
Re: OpenGL easier than I thought
There's a few ways to simulate gravity:
Easy:
The easiest way is to simply change the velocity to negative and have the object fall at a constant speed.
In many cases it won't look much different and this method will suffice.
Realistic:
Create a scale for your game. For instance 5 pixels might equal a meter.
Velocity = Acceleration * Time
Distance = Velocity * Time
Eventually it hits the ground and your collision takes over (or it falls off the screen).
EDIT: Done editing.
Easy:
The easiest way is to simply change the velocity to negative and have the object fall at a constant speed.
In many cases it won't look much different and this method will suffice.
Realistic:
Create a scale for your game. For instance 5 pixels might equal a meter.
Velocity = Acceleration * Time
Distance = Velocity * Time
Code: Select all
//Where time is equal to the number of seconds since the last loop: (SDL_GetTicks() - oldTime) / 1000
yVelocity = yVelocity + ((9.81 * 5) * time); //Multiply by number of pixels in a meter
yPosition = yPosition + (yVelocity * time) //Calculate new position
EDIT: Done editing.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!
- Falco Girgis
- Elysian Shadows Team
- Posts: 10294
- Joined: Thu May 20, 2004 2:04 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Dreamcast, SNES, NES
- Programming Language of Choice: C/++
- Location: Studio Vorbis, AL
- Contact:
Re: OpenGL easier than I thought
...question.
What does gravity have to do with OpenGL?
What does gravity have to do with OpenGL?
- dandymcgee
- ES Beta Backer
- Posts: 4709
- Joined: Tue Apr 29, 2008 3:24 pm
- Current Project: https://github.com/dbechrd/RicoTech
- Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
- Programming Language of Choice: C
- Location: San Francisco
- Contact:
Re: OpenGL easier than I thought
GyroVorbis wrote:...question.
What does gravity have to do with OpenGL?
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!
- davidthefat
- Chaos Rift Maniac
- Posts: 529
- Joined: Mon Nov 10, 2008 3:51 pm
- Current Project: Fully Autonomous Robot
- Favorite Gaming Platforms: PS3
- Programming Language of Choice: C++
- Location: California
- Contact:
Re: OpenGL easier than I thought
Actual 3d environment... Now that you mention it... IDK reallyGyroVorbis wrote:...question.
What does gravity have to do with OpenGL?
- rolland
- Chaos Rift Regular
- Posts: 127
- Joined: Fri Dec 21, 2007 2:27 pm
- Current Project: Starting an Android app soon
- Favorite Gaming Platforms: PS1, N64
- Programming Language of Choice: C++
- Location: Michigan, US
Re: OpenGL easier than I thought
That's why he couldn't figure it out.GyroVorbis wrote:...question.
What does gravity have to do with OpenGL?
I'll write a signature once I get some creativity and inspiration...
- Ratstail91
- Chaos Rift Newbie
- Posts: 8
- Joined: Sun Feb 01, 2009 1:58 am
Re: OpenGL easier than I thought
HUH? why does everything go over my head all the time?
not that you'd use it but, I'd do this.
yeah, whatever.
not that you'd use it but, I'd do this.
Code: Select all
float fspeed = 0;
while(falling == true)
{
fspeed += 0.1;
y -= fspeed;
}