The NeverFall is First Personal Shooter mod for Half-Life 2. 7 years ago The Combines was expelled. Now new life started. Alyx and Gordon live together now. But something goes not as good as should. New danger threatens humanity...
Posts | ||
---|---|---|
Analog Jumping | Locked | |
Thread Options | ||
Feb 11 2009 Anchor | ||
We are going to use analog jumping in our mod. To continue Ibutsu's series on Game Movement, I take a look at setting up an analog jumping system. This tutorial details how to incorporate analog "float" jumping into your mod. The idea behind this jump style is that the longer you hold down jump, the higher you rise into the air. After a specified period of time, you can no longer go up, and you will start to fall. As you are falling, if you release the jump key and hit it again, you will begin to decelerate until you reach a minimum fall velocity, at which point you will sustain that fall rate as long as jump is held down. By changing one line of code, you can alternate between allowing the user to "catch" his/her self once or as many times as he/she wants. First we will overload CGameMovement::CheckJumpButton function in the CSDKGameMovement class. 1. In sdk_gamemovement.cpp, declare the function bool CheckJumpButton(); in the public section of the class. CODE CSDKGameMovement(); 2. Add the function body below the CSDKGameMovement constructor. CODE Ok, that parts done. Now we need to start adding some actual code. 3. First, we need to declare some variables we are going to be using for our jump code. Add the following variables to the private section of the CSDKGameMovement class declaration in sdk_gamemovement.cpp: CODE float m_fLastJumpTime; //the last jump time (seconds) bool currInAir; //are we currently in the air The comments attempt to describe the purpose of each of the member variables, but dont worry about it that much quite yet. 4. Next we want to initialize all that stuff in the CSDKGameMovement constructor. So still in sdk_gamemovement.cpp, edit the constructor to look like this: CODE 5. Ok, the next step is to actually start coding this thing. First we need some basic jump handling logic (ie, what to do if we're dead, in water, on a ladder, etc). Basically, we're copying and pasting this code from CGameMovement::CheckJumpButton(), but here it is in a slightly more compressed format. CODE // See if we are waterjumping. If so, decrement count and return. m_iNumJumps = 0; // If we are in the water most of the way... if(player->GetWaterType() == CONTENTS_WATER) // We move up a certain amount // play swiming sound // Don't allow jumping for the following } The comments explain what is going on in there. Essentially, we are preventing jumping in some cases, handling jumps from underwater and in the water, and when you're in the proccess of ducking. 6. Next, there are a few things we need to be able to do to make float jumping work right. -We need to know which calls to this function are the result of a new press of the jump button, and we need to know what time these calls occur at, AND we need to know how many times jump has been pressed. At the end of the CheckJumpButton function, add the following code: CODE //if this was a new jump, incrememt the jump count, make it first time through, and log the time -We need to know the current and previous state of the player being on the ground or in the air. Right after the above code, add the following: CODE 7. Ok, now its time to sort out the various jump cases. Here it is with tons of comments and an explanation of whats happening at the end: CODE //sanity check. if we're not in the air and you're jumping then this is your first jump //play sound and animation for jumping off ground //if we were supposed to supress pogo jumps // In the air now, so we dont have a ground entity //figure out if the ground will effect our jump // If we are ducking, only allow a normal jump //allow gravity to do its thing //stick the results of our meddling into the jump results vector // Flag that we jumped. return true; Ok, so what we're doing is checking to see if we're in the air or not. If we are in the air we're either going to be continuing upward, or floating downward. If we're going up, and we're past the time limit on going up, we cant keep going up. If we're on the ground, then we are allowed to start jumping from scratch. Pogo jumping is very irritating, so there is special code in there to handle it. So thats it, now you need to do a few things to get this thing to compile, so onward!... 8. We need to declare CSDKGameMovement a friend class of C_BasePlayer so that we can access the private members (/me chuckles) of the C_BasePLayer class . To do this, go into c_baseplayer.h and search for statement "friend class CGameMovement" Right below that series of friend class declarations, add CSDKGameMovement as a friend class. CODE 9. Finally, you have to stick the different vars I was using for determining acceleration, deceleration, jump limit, etc. So go to the top of sdk_gamemovement.cpp and add the following. The values associated with each #define are the ones I have been playing with lately, but feel free to experiment. CODE Well congratulations. Thats it. You're done. I have to go now... I think I have a... Food... in the oven. -Hopper-
Copyright 2007 TheWavelength.net. All Rights Reserved. Any intellectual data is property of its respective owner(s).
Wavelength version: 3.0.0.9
Edited by: nuxdie |
Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.