Help with gravity please

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
Ninjaturtles
Posts: 1
Joined: July 19th, 2012, 9:10 pm

Help with gravity please

Post by Ninjaturtles » July 21st, 2012, 2:04 pm

hello every1, i am wasting alot of time trying to fix gravity to a 2d platformer, can any1 walk me trough it ?

Lorth
Posts: 139
Joined: July 19th, 2012, 4:12 pm

Re: Help with gravity please

Post by Lorth » July 21st, 2012, 5:11 pm

Hey!

Do you have any started project yet?

I am only a beginner but one way should probably be that, in every update of the Player, just set y++; that would make the Player fall down with 1 pixel every update intill he either reaches a ground or fall off the screen..

someone else might have an more advanced and better way. :D
but this could be one way.

good luck :D

User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: Help with gravity please

Post by LuX » July 21st, 2012, 5:20 pm

Yep, a pseudo code would be; if character has not collided with terrain, then character y will be reduced by gravity.

If you wanted it more realistic, something like an accelerating hyperbola gravity might be good.
ʕ •ᴥ•ʔ

Lorth
Posts: 139
Joined: July 19th, 2012, 4:12 pm

Re: Help with gravity please

Post by Lorth » July 21st, 2012, 6:55 pm

Lux, for how long have you programmed?

just think some of your uploaded things on the forum is great, and i learn alot from them :D and learn even more from trying to modify for own games. :D

the square game with dust is awsome! can't stop playing it :D

User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: Help with gravity please

Post by LuX » July 21st, 2012, 7:28 pm

About 2 to 3 years of Visual basic. But there I never really learned to code anywhere properly so I pretty much learned the syntax and had to figure out most of the stuff by my self. And it was mostly application programming, rather than game programming.

Actual, and proper, game programming I have done since I found chili's tutorials. So that's about exactly 3 months of c++ I've been learning now.
ʕ •ᴥ•ʔ

User avatar
npissoawsome
Posts: 114
Joined: June 8th, 2012, 3:01 pm

Re: Help with gravity please

Post by npissoawsome » July 21st, 2012, 9:23 pm

What I do is check if the player is actually above the floor, and if so get some proposed co-ordinates (his position minus some value on the y axis) and check to see if that position collides with anything, if it does, nothing happens, if it doesn't collide, the character goes to these proposed co-ordinates

Post Reply