Thread: Doing ladder
View Single Post
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 12-22-2008 , 04:40   Re: Doing ladder
Reply With Quote #17

Stand by.

Was simply copy/pasting laddermove code from HLSDK, gonna share what i'v done so anyone can work on it.

Code:
void PM_LadderMove( physent_t *pLadder )
{
	vec3_t		ladderCenter;
	trace_t		trace;
	qboolean	onFloor;
	vec3_t		floor;
	vec3_t		modelmins, modelmaxs;

	if ( pmove->movetype == MOVETYPE_NOCLIP )
		return;

	pmove->PM_GetModelBounds( pLadder->model, modelmins, modelmaxs );

	VectorAdd( modelmins, modelmaxs, ladderCenter );
	VectorScale( ladderCenter, 0.5, ladderCenter );

	pmove->movetype = MOVETYPE_FLY;

	// On ladder, convert movement to be relative to the ladder

	VectorCopy( pmove->origin, floor );
	floor[2] += pmove->player_mins[pmove->usehull][2] - 1;

	if ( pmove->PM_PointContents( floor, NULL ) == CONTENTS_SOLID )
		onFloor = true;
	else
		onFloor = false;

	pmove->gravity = 0;
	pmove->PM_TraceModel( pLadder, pmove->origin, ladderCenter, &trace );
	if ( trace.fraction != 1.0 )
	{
		float forward = 0, right = 0;
		vec3_t vpn, v_right;

		AngleVectors( pmove->angles, vpn, v_right, NULL );
		if ( pmove->cmd.buttons & IN_BACK )
			forward -= MAX_CLIMB_SPEED;
		if ( pmove->cmd.buttons & IN_FORWARD )
			forward += MAX_CLIMB_SPEED;
		if ( pmove->cmd.buttons & IN_MOVELEFT )
			right -= MAX_CLIMB_SPEED;
		if ( pmove->cmd.buttons & IN_MOVERIGHT )
			right += MAX_CLIMB_SPEED;

		if ( pmove->cmd.buttons & IN_JUMP )
		{
			pmove->movetype = MOVETYPE_WALK;
			VectorScale( trace.plane.normal, 270, pmove->velocity );
		}
		else
		{
			if ( forward != 0 || right != 0 )
			{
				vec3_t velocity, perp, cross, lateral, tmp;
				float normal;

				//ALERT(at_console, "pev %.2f %.2f %.2f - ",
				//	pev->velocity.x, pev->velocity.y, pev->velocity.z);
				// Calculate player's intended velocity
				//Vector velocity = (forward * gpGlobals->v_forward) + (right * gpGlobals->v_right);
				VectorScale( vpn, forward, velocity );
				VectorMA( velocity, right, v_right, velocity );

				
				// Perpendicular in the ladder plane
	//					Vector perp = CrossProduct( Vector(0,0,1), trace.vecPlaneNormal );
	//					perp = perp.Normalize();
				VectorClear( tmp );
				tmp[2] = 1;
				CrossProduct( tmp, trace.plane.normal, perp );
				VectorNormalize( perp );


				// decompose velocity into ladder plane
				normal = DotProduct( velocity, trace.plane.normal );
				// This is the velocity into the face of the ladder
				VectorScale( trace.plane.normal, normal, cross );


				// This is the player's additional velocity
				VectorSubtract( velocity, cross, lateral );

				// This turns the velocity into the face of the ladder into velocity that
				// is roughly vertically perpendicular to the face of the ladder.
				// NOTE: It IS possible to face up and move down or face down and move up
				// because the velocity is a sum of the directional velocity and the converted
				// velocity through the face of the ladder -- by design.
				CrossProduct( trace.plane.normal, perp, tmp );
				VectorMA( lateral, -normal, tmp, pmove->velocity );
				if ( onFloor && normal > 0 )	// On ground moving away from the ladder
				{
					VectorMA( pmove->velocity, MAX_CLIMB_SPEED, trace.plane.normal, pmove->velocity );
				}
				//pev->velocity = lateral - (CrossProduct( trace.vecPlaneNormal, perp ) * normal);
			}
			else
			{
				VectorClear( pmove->velocity );
			}
		}
	}
}
PHP Code:
/*    Copyright © 2008, ConnorMcLeod

    Ladder Test is free software;
    you can redistribute it and/or modify it under the terms of the
    GNU General Public License as published by the Free Software Foundation.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Ladder Test; if not, write to the
    Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/

#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>
#include <xs>

#define PLUGIN "Ladder Test"
#define AUTHOR "ConnorMcLeod"
#define VERSION "0.0.1"

#define MAX_CLIMB_SPEED    200.0

new gOnLadder[33];

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)

    
RegisterHam(Ham_Touch"func_wall""World_Touch")
    
RegisterHam(Ham_Touch"func_breakable""World_Touch")
//    RegisterHam(Ham_Touch, "worldspawn", "World_Touch")

    
register_forwardFM_PlayerPostThink "PlayerPostThink")
}

public 
World_Touch(iEntid)
{
    if( !
is_user_alive(id) )
    {
        return
    }

    if( 
pev(idpev_groundentity) == iEnt )
    {
            return
    }
    
gOnLadder[id] = iEnt
}

public 
PlayerPostThink(id)
{
    if( !
gOnLadder[id] || pev(idpev_movetype) == MOVETYPE_NOCLIP)
    {
        return
    }

    static 
pLadder pLadder gOnLadder[id]
    static 
bool:onFloor
    
static Float:modelmins[3], Float:modelmaxs[3], Float:ladderCenter[3], Float:floor[3],
    
Float:origin[3]

    
pev(pLadderpev_minsmodelmins)
    
pev(pLadderpev_maxsmodelmaxs)
    
xs_vec_addmodelminsmodelmaxsladderCenter );
    
xs_vec_mul_scalarladderCenter0.5ladderCenter );

    
set_pev(idpev_movetypeMOVETYPE_FLY)

    
pevidpev_originorigin )
    
xs_vec_copy(originfloor)
    
pev(idpev_minsmodelmins)
    
floor[2] += modelmins[2] - 1

    
if ( engfuncEngFunc_PointContentsfloor ) == CONTENTS_SOLID )
        
onFloor true;
    else
        
onFloor false;

    
//set_pev(id, pev_gravity, 0.0) // useless ?

    //PM_TraceModel( pLadder, pmove->origin, ladderCenter, &trace )
//    engfunc(EngFunc_TraceModel, origin, ladderCenter, HULL_HUMAN, pLadder, 0);

    
static Float:flTraceFraction
    global_get
glb_trace_fractionflTraceFraction )
    if ( 
flTraceFraction == 1.0 )
        return

    static 
iButton iButton pev(idpev_button)
    static 
Float:flVelocity[3]

    static 
Float:_forwardFloat:right
    
static Float:vpn[3], Float:v_right[3];
    
_forward 0.0
    right 
0.0

    
new Float:flAngles[3]
    
pev(idpev_anglesflAngles)
    
engfunc(EngFunc_AngleVectorsflAnglesvpnv_right0.0);

    if ( 
iButton IN_BACK )
        
_forward -= MAX_CLIMB_SPEED;
    if ( 
iButton IN_FORWARD )
        
_forward += MAX_CLIMB_SPEED;
    if ( 
iButton IN_MOVELEFT )
        
right -= MAX_CLIMB_SPEED;
    if ( 
iButton IN_MOVERIGHT )
        
right += MAX_CLIMB_SPEED;

    new 
Float:flTracePlaneNormal[3]
    if ( 
iButton IN_JUMP )
    {
        
set_pev(idpev_movetypeMOVETYPE_WALK)
        
global_get(glb_trace_plane_normalflTracePlaneNormal)        
        
xs_vec_mul_scalar(flTracePlaneNormal270.0flVelocity)
        
set_pev(idpev_velocityflVelocity)
    }
    else
    {
        if( 
_forward || right )
        {
            static 
Float:velocity[3], Float:perp[3], Float:cross[3], Float:lateral[3], Float:tmp[3]
            static 
Float:normal

            xs_vec_mul_scalar
(vpn_forwardvelocity)
            
VectorMAvelocityrightv_rightvelocity )

            
tmp[0] = 0.0
            tmp
[1] = 0.0
            tmp
[2] = 1.0;
            
global_get(glb_trace_plane_normalflTracePlaneNormal)
            
xs_vec_crosstmpflTracePlaneNormalperp );
            
xs_vec_normalize(perpperp)

            
// decompose velocity into ladder plane
            
normal xs_vec_dotvelocityflTracePlaneNormal );
            
            
// This is the velocity into the face of the ladder
            
xs_vec_mul_scalar(flTracePlaneNormalnormalcross)

            
// This is the player's additional velocity
            
xs_vec_subvelocitycrosslateral );

            
// This turns the velocity into the face of the ladder into velocity that
            // is roughly vertically perpendicular to the face of the ladder.
            // NOTE: It IS possible to face up and move down or face down and move up
            // because the velocity is a sum of the directional velocity and the converted
            // velocity through the face of the ladder -- by design.
            
xs_vec_cross(flTracePlaneNormalperptmp)
            
VectorMAlateral, -normaltmpvelocity );
            
            if ( 
onFloor && normal )    // On ground moving away from the ladder
            
{
                
VectorMAvelocityMAX_CLIMB_SPEEDflTracePlaneNormalvelocity );
            }
            
set_pev(idpev_velocityvelocity)
        }
        else
        {
            
set_pev(idpev_velocityFloat:{0.0,0.0,0.0})
            return
        }
    }
    
gOnLadder[id] = 0
}

VectorMA(const Float:veca[3], Float:scale, const Float:vecb[3], Float:vecc[3])
{
    
vecc[0] = veca[0] + scale*vecb[0];
    
vecc[1] = veca[1] + scale*vecb[1];
    
vecc[2] = veca[2] + scale*vecb[2];

__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline