Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Gravity

Author
Message
Oster200
13
Years of Service
User Offline
Joined: 21st Jan 2011
Location:
Posted: 21st Jan 2011 19:59
I need help on how to make gravity. If you could just tell me the basics of gravity i might be able to figure it out. oh yes btw im making a 2d game and i want my main player to have gravity. Thanks in Advanced.
DeadTomGC
14
Years of Service
User Offline
Joined: 11th Aug 2010
Location: LU
Posted: 22nd Jan 2011 02:44
Ok, so the formula in physics for determining the velocity of an object that has a force that causes constant acceleration is v(t)=Vi+a*t.
first thing you will want to do is determine what your scale for time will be. Refreshes or actual time.
It will probably be refreshes.(this is much easier)
If it is refreshes then forget t, and let vi be the previous v(t)(from the last sync).
So you should have this command in EVERY refresh
Vy=Vy+g;
g is the gravity strength you want. You figure that out.
Then, after other forces ajust the Vy, you should have a command like this:
dbSprite(i,dbSpriteX(i),dbSpriteY(i)+Vy,dbSpriteImage(i));
Here you should check your collisions.
If there is a collision then you know to only affect your y position and velocity. Just remember to change Vy to 0 when the object hits the ground otherwise the game will work until the speed become so great that it teleports off the screen.

I'll get a new signature someday.
Oster200
13
Years of Service
User Offline
Joined: 21st Jan 2011
Location:
Posted: 22nd Jan 2011 16:20
DeadTom wont i need a for loop with this because i see there are (i) in it so if you could tell me that would be great? You were very helpful at least now i now where to start off.

Login to post a reply

Server time is: 2024-09-28 13:59:07
Your offset time is: 2024-09-28 13:59:07