ground?

• 04-08-2010, 07:56 PM
ground?
This may have been asked, but I wasn't sure what to search for exactly. I want to make "ground" for a game, how would you go about doing that? I also wanted gravity, and there will be holes and stuff, so the character should stand on the ground, and also will be able to jump and stuff. How would I go about doing this?
• 04-08-2010, 09:00 PM
Fubarable
Welcome to the forum.

You may wish to tell the details of your problem.
• 04-09-2010, 07:36 PM
Well it kinda is the problem, it's a very generic question I have no idea where to start. I did figure out the ground thing, was very simple once I actually did it, but I still have no idea where to begin making gravity. Would it be easier to make each sprite "fall" when nothing is underneath it or just have something more like real gravity?
• 04-09-2010, 09:25 PM
iluxa
Think Physics.

if your character stands on the ground (its Y coordinate is same as Y coordinate of the ground), there's nothing to do.

if however your character is above the ground, gravity kicks in. from physics:

v = at
y = vt

a = acceleration
v = velocity
y = y-coordinate
t = time

acceleration is constant. On real Earth, it equals 9.8, for your game, pick a value that looks good.

Have a thread that kicks in every 50 milliseconds, for example, and does this:

// timeElapsed = 50 milliseconds
velocityNew = velocityOld + GRAVITY_CONSTANT * timeElapsed;
yCoordinateNew = yCoordinateOld + velocityNew * timeElapsed;

and you're done! just make sure to stop this thread as soon as the character hits the ground
• 04-13-2010, 06:01 AM