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 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:
| | | pmtrace_t trace; vec3_t end, right; float smove;
|
A little way down the function find this line:
| | | if ( pmove->onground == -1 )
|
Before it put this little chunk of code, then I will explain how it works:
| | | smove = 16; AngleVectors(pmove->angles, NULL, right, NULL); if ( pmove->onground == -1) { end[2] = pmove->origin[2]; if (pmove->cmd.buttons & IN_JUMP && pmove->cmd.buttons & IN_MOVELEFT) { if(pmove->oldbuttons & IN_JUMP) return; for (i=0; i<2; i++) end[i] = pmove->origin[i] + right[i] * smove;
trace = pmove->PM_PlayerTrace (pmove->origin, end, PM_WORLD_ONLY, -1 ); if ( trace.fraction < 1.0 ) { 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; return; } } else if (pmove->cmd.buttons & IN_JUMP && pmove->cmd.buttons & IN_MOVERIGHT) { if(pmove->oldbuttons & IN_JUMP) return;
for (i=0; i<2; i++) end[i] = pmove->origin[i] + right[i] * -smove; trace = pmove->PM_PlayerTrace (pmove->origin, end, PM_WORLD_ONLY, -1 ); if ( trace.fraction < 1.0 ) { 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; return; } } }
|
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 Comments
Showing comments 1-8
|
Tutorial fixed, hopefully for the last time ;) |
|
|
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 |
|
Well look at player.cpp ;) void CBasePlayer::SetAnimation( PLAYER_ANIM playerAnim ) |
|
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? |
|
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. |
|
|
where should I put the first variable? |
|
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." :) |
|
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.
|
296 Approved Articless
5 Pending Articles
3940 Registered Members
0 People Online (15 guests)
|
|