Welcome, Guest! Login | Register

Wall Jumping [Print this Article]
Posted by: X-0ut
Date posted: May 08 2003
User Rating: 5 out of 5.0
Number of views: 5095
Number of comments: 8
Description: Nasty pm_shared

UPDATE: All 3 of us overlooked this ages ago! I only noticed it today while I was messing with one of my other mods that used it! The code has been updated to completely remove the crash.
The problem was rather simple; it would create the "dir" vector, and then add it into the origin, which in most cases would only end up being 3 units difference, not 16 like it was supposed to! We all overlooked the fact that you need to create the end point via 'end = origin + direction * 16'

Suffice it to say, X-0ut and I are embarrassed =)
-omega


This little tutorial will teach you how to give the player a new ability - walljumping user posted image
To make sure you actually learn something im going to only include walljumping from side to side, so if you want the player to jump forward/backs from a wall you will need to incorporate that yourself (its really easy actually).

Here goes, we are going to be working in pm_shared.c only, so open it up and find the pm_jump function, we'll need to declare some new variables and since this is C not C++ we will have to declare them at the begining of the function.

These are the variables needed:
 CODE (C++) 

    //XWJ
    pmtrace_t trace;
    vec3_t  end, right; //omega; change, add right
    float  smove; //omega; remove fmove
    //XWJ

A little way down the function find this line:
 CODE (C++) 

    // No more effect
    if ( pmove->onground == -1 )

Before it put this little chunk of code, then I will explain how it works:
 CODE (C++) 

    //WALL JUMPING; omegafied
    //the distance in units away from the center of the player to trace for a wall
    //this could be adjusted to take the players bounding box into account, but this works for standard hl
    //bounding boxes. adjust as necessary.
    smove = 16;
    AngleVectors(pmove->angles, NULL, right, NULL); //convert our angles (not view) and get the right vector
    if ( pmove->onground == -1)//check not on ground(only wall jump when in air)
    {
        end[2] = pmove->origin[2]; //make sure the z component is always the same for all checks.
        if (pmove->cmd.buttons & IN_JUMP && pmove->cmd.buttons & IN_MOVELEFT)
        {
            if(pmove->oldbuttons & IN_JUMP) //if we aren't holding the button still
                return;
            // check wall to left.
            for (i=0; i<2; i++)  //setup the "end" vector ('smove' units to the left of the player)
                end[i] = pmove->origin[i] + right[i] * smove;

            trace = pmove->PM_PlayerTrace (pmove->origin, end, PM_WORLD_ONLY, -1 ); //trace to the world only!
           
            if ( trace.fraction < 1.0 )//if there was a wall
            {
                //add velocity in opposite direction
                for (i =0; i < 2; i++)
                    pmove->velocity[i] = right[i] * -PLAYER_LONGJUMP_SPEED * 1.1;

                pmove->velocity[2] = sqrt(2 * 800 * 56.0);
                pmove->oldbuttons &= ~IN_JUMP; //allow us to walljump again, if we get against another wall that is
                return; //omega; get out! (so flags don't get reset below if we're still holding the key!
            }
        }
        else if (pmove->cmd.buttons & IN_JUMP && pmove->cmd.buttons & IN_MOVERIGHT)
        {
            if(pmove->oldbuttons & IN_JUMP)
                return;

            // check wall to left.
            for (i=0; i<2; i++) //omega; check the opposite direction
                end[i] = pmove->origin[i] + right[i] * -smove;
           
            trace = pmove->PM_PlayerTrace (pmove->origin, end, PM_WORLD_ONLY, -1 );
            if ( trace.fraction < 1.0 )//if there was a wall
            {
                //add velocity in opposite direction
                for (i =0; i < 2; i++)
                    pmove->velocity[i] = right[i] * PLAYER_LONGJUMP_SPEED * 1.1;
                pmove->velocity[2] = sqrt(2 * 800 * 56.0);
                pmove->oldbuttons &= ~IN_JUMP;
                //omega; allow us to walljump again (if we get against another wall that is)
                return; //omega;get out! (so flags don't get reset below if we're still holding the key!
            }
        }
    }
    //END WALLJUMPING


Right well thats it, if you compile that both server and client you will now be able to jump from wall to wall.
Remember, you have to hold the strafe keys in the direction you wan't to jump; ie: if the wall is to your right, when you're in the air against the wall you want to hold moveleft and tap jump again.

Well thats it, I hope somebody learned something and that I didnt totally screw things up. BTW, walljumping takes some practice to become fairly good at user posted image

Rate This Article
This article is currently rated: 5 out of 5.0 (5 Votes)

You have to register to rate this article.
User Comments Showing comments 1-8

Posted By: omega on Sep 28 2003 at 18:01:20
Tutorial fixed, hopefully for the last time ;)

Posted By: CrossFire on Nov 09 2003 at 01:22:20
I know you would have to do some modeling, but how would you add custom animations for like lets say when you jump of the wall to the right, you see you chracter look like he jumps off the wall, and not just the regular jump. thanks

Posted By: InternetNightmare on Apr 30 2004 at 11:07:39
Well look at player.cpp ;)
void CBasePlayer::SetAnimation( PLAYER_ANIM playerAnim )

Posted By: Teddy on Jun 24 2004 at 19:22:57
Another simpler way to do this is to do it in the ClipVelocity function.

Alls you gotta do is check if the clipsurface is a wall, then check if the player is in the air, and holding jump, then add 280 odd to the z velocity, and multiply the clipvelocity by 2 (so they push back off the wall).

Simple, huh?

Posted By: ledjon on Dec 13 2004 at 09:02:22
Why does this have to be done in pm_shared at all? This seems like something you could simulate in player.cpp's Jump method. I haven't looked into it at all (perhaps will later), but I was wondering if there is a specific reason that I'm not aware of here.

Thanks.

Posted By: Jorg40 on Jan 06 2005 at 10:37:23
where should I put the first variable?

Posted By: InternetNightmare on Mar 05 2005 at 06:36:32
In the begining of the function. :)

"Here goes, we are going to be working in pm_shared.c only, so open it up and find the pm_jump function, we'll need to declare some new variables and since this is C not C++ we will have to declare them at the begining of the function." :)

Posted By: Jorg40 on Apr 29 2005 at 14:07:16
Can someone explain step by step on how to add animations to left and right?

Note: I do only weapons coding, and night vision pluss stuff like cloaking and medic. Thats my are, not anims... Can anyone help?


You must register to post a comment. If you have already registered, you must login.

Latest Articles
3rd person View in Multiplayer
Half-Life 2 | Coding | Client Side Tutorials
How to enable it in HL2DM

By: cct | Nov 13 2006

Making a Camera
Half-Life 2 | Level Design
This camera is good for when you join a map, it gives you a view of the map before you join a team

By: slackiller | Mar 04 2006

Making a camera , Part 2
Half-Life 2 | Level Design
these cameras are working monitors that turn on when a button is pushed.

By: slackiller | Mar 04 2006

Storing weapons on ladder
Half-Life 2 | Coding | Snippets
like Raven Sheild or BF2

By: British_Bomber | Dec 24 2005

Implementation of a string lookup table
Half-Life 2 | Coding | Snippets
A string lookup table is a set of functions that is used to convert strings to pre-defined values

By: deathz0rz | Nov 13 2005


Latest Comments
Where do we go from here
General | News
By: MIFUNE | Jun 09 2008
 
The Input/Output system
Half-Life 2 | Level Design
By: nazitaco | Dec 23 2007
 
Where do we go from here
General | News
By: Rob_F | Nov 22 2007
 
Rescaling Half-Life
Half-Life | Coding | Shared Tutorials
By: christoph | Nov 12 2007
 
GameUI
Half-Life 2 | Coding | Client Side Tutorials
By: Evil_j | Oct 29 2007
 
3 State Zoom For Any Weapon
Half-Life 2 | Coding | Server Side Tutorials
By: Ennuified | Oct 18 2007
 
Storing weapons on ladder
Half-Life 2 | Coding | Snippets
By: cct | Sep 07 2007
 
CTF Gameplay Part 1
Half-Life | Coding | Shared Tutorials
By: DarkNight | Aug 28 2007
 
CTF Gameplay Part 1
Half-Life | Coding | Shared Tutorials
By: deedok | Aug 20 2007
 
Debugging your half-life 2 mod
Half-Life 2 | Coding | Articles
By: blackshark | Aug 17 2007
 

Site Info
296 Approved Articless
5 Pending Articles
3940 Registered Members
0 People Online (15 guests)
About - Credits - Contact Us

Wavelength version: 3.0.0.9
Valid XHTML 1.0! Valid CSS!