character jumping

This is a discussion on character jumping within the Game Programming forums, part of the General Programming Boards category; Hello, I'm having a bit of trouble with getting my character to jump, I've looked around the forums and haven't ...

  1. #1
    Registered User
    Join Date
    Jun 2012
    Posts
    1

    character jumping

    Hello, I'm having a bit of trouble with getting my character to jump, I've looked around the forums and haven't found a solution to my problem so yeah, here I am :P

    So far I have this:

    Code:
    if(GetAsyncKeyState(VK_SPACE)) person1.jump = true;
    
    
    if(person1.jump == true){
            person1.y += person1.jumpVel;
            person1.jumpVel = (person1.jumpVel - person1.gravity);
        
            if(groundCollision()){
                person1.jumpVel = person1.oldy;
                person1.jump = false;
            }
        }
    The value of jumpVel is 2; and gravity is 0.2;
    That's in my main game loop. The problem is when I hit space the character goes up and doesn't stop, and then the program freezes.

    Any help would be most appreciated .

  2. #2
    Registered User
    Join Date
    Oct 2006
    Posts
    250
    I am not an expert in Windows programming, but the description of GetAsyncKeyState says the following about the return value:

    ... If the most significant bit is set, the key is down ...
    ...
    The return value is zero for the following cases:

    The current desktop is not the active desktop
    The foreground thread belongs to another process and the desktop does not allow the hook or the journal record.
    ...
    Therefore GetAsyncKeyState(VK_SPACE) always returns true, you should instead check the most significant bit of the return value (it's a SHORT not a BOOL).
    iMalc: Your compiler doesn't accept misspellings and bad syntax, so why should we?
    justin777: I have no idea what you are talking about sorry, I use a laptop and there is no ascii eject or something

  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    Jumping is done by applying a force in the +Y direction (if +Y is up in your system) and then letting the physics take care of it from there. Your physics should already be applying a down force on dynamic objects.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Jumping to OOP in C++ from C
    By meadhikari in forum C++ Programming
    Replies: 6
    Last Post: 07-16-2010, 05:26 AM
  2. Jumping in the code...
    By AdampqmabA in forum C++ Programming
    Replies: 24
    Last Post: 10-06-2008, 05:34 PM
  3. Jumping between functions
    By Nexus-ZERO in forum C Programming
    Replies: 8
    Last Post: 01-14-2008, 02:47 AM
  4. Jumping Script
    By Krak in forum Game Programming
    Replies: 5
    Last Post: 01-12-2004, 02:19 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21