Results 1 to 4 of 4

Thread: character jump

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2002
    Posts
    17

    character jump

    I am making a game in 2d environment with a 2d character that moves left and right only. I want to make him jump, but have no Idea how to make him, even then if he jumps how would you make him land on a platform above the ground?................need help

  2. #2
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    you'll need a loop where the movement code is....
    then in the loop you'll have to check for collition with any platform in the game...
    here you can get some code for jumping: http://www.vbforums.com/showthread.p...hreadid=221891
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  3. #3
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    This code will make you jump:

    VB Code:
    1. Gravity = 0.5
    2. YSpeed = 20

    And this you run every frame to continue the jump, if needed:

    VB Code:
    1. If NotOnGround = True Then
    2.     YSpeed = YSpeed - Gravity
    3. End If
    4.  
    5. Y = Y - YSpeed 'If it jumps "down" or gives you any error, try changing this to + instead

    Of course, you need to set NotOnGround to False if it's not colliding with the ground. A very simple way to do this is check if the Y is smaller than a certain value, like this:

    VB Code:
    1. If Y < 100 Then
    2.     NotOnGround = True
    3. Else
    4.     NotOnGround = False
    5. End If
    6. 'Now that we know if it's on ground or not, you can run the code I gave you above

    That should do it! Remember that the variables must be accessible from all Subs. You know about variables' scopes right? Oh, feel free to modify those values, this code I gave you might not even work at all unless you adjust them a little...
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  4. #4
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    One more thing, look for the Lander Game Tutorial at vbworld.net , it explains physics like jumping and falling in a very accessible way. (so YOU can understand it better, k? )
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

Posting Permissions

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



Click Here to Expand Forum to Full Width