Results 1 to 5 of 5

Thread: ground?

  1. #1
    Join Date
    Apr 2010
    Posts
    10
    Rep Power
    0

    Default 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?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

  3. #3
    Join Date
    Apr 2010
    Posts
    10
    Rep Power
    0

    Default

    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?

  4. #4
    iluxa is offline Senior Member
    Join Date
    Mar 2010
    Posts
    266
    Rep Power
    5

    Default

    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

  5. #5
    Join Date
    Apr 2010
    Posts
    10
    Rep Power
    0

    Default

    thanks you made me think along a path that couldn't come to me haha, sorry i took so long to respond

Similar Threads

  1. Back Ground Midlet
    By krmlkr in forum CLDC and MIDP
    Replies: 1
    Last Post: 03-06-2008, 01:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •