void CASW_Drone_Movement::WalkMove() { // Add in any base velocity to the current velocity. VectorAdd (mv->m_vecVelocity, m_pNPC->GetBaseVelocity(), mv->m_vecVelocity ); // if we're barely moving, then zero the velocity and stop float spd = VectorLength( mv->m_vecVelocity ); if ( spd < 1.0f || m_flInterval <= 0) { mv->m_vecVelocity.Init(); // Now pull the base velocity back out. Base velocity is set if you are on a moving object, like a conveyor (or maybe another monster?) VectorSubtract( mv->m_vecVelocity, m_pNPC->GetBaseVelocity(), mv->m_vecVelocity ); return; } // first try just moving to the destination Vector dest; dest[0] = mv->GetAbsOrigin()[0] + mv->m_vecVelocity[0]*m_flInterval; dest[1] = mv->GetAbsOrigin()[1] + mv->m_vecVelocity[1]*m_flInterval; dest[2] = mv->GetAbsOrigin()[2]; trace_t pm; UTIL_TraceEntity( m_pNPC, mv->GetAbsOrigin(), dest, MASK_NPCSOLID, &pm ); //TraceBBox( mv->GetAbsOrigin(), dest, MASK_NPCSOLID, m_pNPC->GetCollisionGroup(), pm ); // if we made it all the way there, then set that as our new origin and return if ( pm.fraction == 1 ) { mv->SetAbsOrigin( pm.endpos ); m_pNPC->PhysicsTouchTriggers(); // Now pull the base velocity back out. Base velocity is set if you are on a moving object, like a conveyor (or maybe another monster?) VectorSubtract( mv->m_vecVelocity, m_pNPC->GetBaseVelocity(), mv->m_vecVelocity ); return; } // if NPC started the move on the ground, then try to move up/down steps if ( m_pNPC->GetGroundEntity() != NULL ) { StepMove( dest, pm ); } // Now pull the base velocity back out. Base velocity is set if you are on a moving object, like a conveyor (or maybe another monster?) VectorSubtract( mv->m_vecVelocity, m_pNPC->GetBaseVelocity(), mv->m_vecVelocity ); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CTFGameMovement::WalkMove( void ) { // Get the movement angles. Vector vecForward, vecRight, vecUp; AngleVectors( mv->m_vecViewAngles, &vecForward, &vecRight, &vecUp ); vecForward.z = 0.0f; vecRight.z = 0.0f; VectorNormalize( vecForward ); VectorNormalize( vecRight ); // Copy movement amounts float flForwardMove = mv->m_flForwardMove; float flSideMove = mv->m_flSideMove; // Find the direction,velocity in the x,y plane. Vector vecWishDirection( ( ( vecForward.x * flForwardMove ) + ( vecRight.x * flSideMove ) ), ( ( vecForward.y * flForwardMove ) + ( vecRight.y * flSideMove ) ), 0.0f ); // Calculate the speed and direction of movement, then clamp the speed. float flWishSpeed = VectorNormalize( vecWishDirection ); flWishSpeed = clamp( flWishSpeed, 0.0f, mv->m_flMaxSpeed ); // Accelerate in the x,y plane. mv->m_vecVelocity.z = 0; Accelerate( vecWishDirection, flWishSpeed, sv_accelerate.GetFloat() ); Assert( mv->m_vecVelocity.z == 0.0f ); // Clamp the players speed in x,y. if ( tf2c_groundspeed_cap.GetBool() ) { float flNewSpeed = VectorLength(mv->m_vecVelocity); if (flNewSpeed > mv->m_flMaxSpeed) { float flScale = (mv->m_flMaxSpeed / flNewSpeed); mv->m_vecVelocity.x *= flScale; mv->m_vecVelocity.y *= flScale; } } // Now reduce their backwards speed to some percent of max, if they are travelling backwards // unless they are under some minimum, to not penalize deployed snipers or heavies if ( tf_clamp_back_speed.GetFloat() < 1.0 && VectorLength( mv->m_vecVelocity ) > tf_clamp_back_speed_min.GetFloat() ) { float flDot = DotProduct( vecForward, mv->m_vecVelocity ); // are we moving backwards at all? if ( flDot < 0 ) { Vector vecBackMove = vecForward * flDot; Vector vecRightMove = vecRight * DotProduct( vecRight, mv->m_vecVelocity ); // clamp the back move vector if it is faster than max float flBackSpeed = VectorLength( vecBackMove ); float flMaxBackSpeed = ( mv->m_flMaxSpeed * tf_clamp_back_speed.GetFloat() ); if ( flBackSpeed > flMaxBackSpeed ) { vecBackMove *= flMaxBackSpeed / flBackSpeed; } // reassemble velocity mv->m_vecVelocity = vecBackMove + vecRightMove; } } // Add base velocity to the player's current velocity - base velocity = velocity from conveyors, etc. VectorAdd( mv->m_vecVelocity, player->GetBaseVelocity(), mv->m_vecVelocity ); // Calculate the current speed and return if we are not really moving. float flSpeed = VectorLength( mv->m_vecVelocity ); if ( flSpeed < 1.0f ) { // I didn't remove the base velocity here since it wasn't moving us in the first place. mv->m_vecVelocity.Init(); return; } // Calculate the destination. Vector vecDestination; vecDestination.x = mv->GetAbsOrigin().x + ( mv->m_vecVelocity.x * gpGlobals->frametime ); vecDestination.y = mv->GetAbsOrigin().y + ( mv->m_vecVelocity.y * gpGlobals->frametime ); vecDestination.z = mv->GetAbsOrigin().z; // Try moving to the destination. trace_t trace; TracePlayerBBox( mv->GetAbsOrigin(), vecDestination, PlayerSolidMask(), COLLISION_GROUP_PLAYER_MOVEMENT, trace ); if ( trace.fraction == 1.0f ) { // Made it to the destination (remove the base velocity). mv->SetAbsOrigin( trace.endpos ); VectorSubtract( mv->m_vecVelocity, player->GetBaseVelocity(), mv->m_vecVelocity ); // Save the wish velocity. mv->m_outWishVel += ( vecWishDirection * flWishSpeed ); // Try and keep the player on the ground. // NOTE YWB 7/5/07: Don't do this here, our version of CategorizePosition encompasses this test // StayOnGround(); return; } // Now try and do a step move. StepMove( vecDestination, trace ); // Remove base velocity. Vector baseVelocity = player->GetBaseVelocity(); VectorSubtract( mv->m_vecVelocity, baseVelocity, mv->m_vecVelocity ); // Save the wish velocity. mv->m_outWishVel += ( vecWishDirection * flWishSpeed ); // Try and keep the player on the ground. // NOTE YWB 7/5/07: Don't do this here, our version of CategorizePosition encompasses this test // StayOnGround(); #if 0 // Debugging!!! Vector vecTestVelocity = mv->m_vecVelocity; vecTestVelocity.z = 0.0f; float flTestSpeed = VectorLength( vecTestVelocity ); if ( baseVelocity.IsZero() && ( flTestSpeed > ( mv->m_flMaxSpeed + 1.0f ) ) ) { Msg( "Step Max Speed < %f\n", flTestSpeed ); } if ( tf_showspeed.GetBool() ) { Msg( "Speed=%f\n", flTestSpeed ); } #endif }
void CSDKGameMovement::WalkMove( void ) { #if defined ( SDK_USE_SPRINTING ) float flSpeedCheck = m_pSDKPlayer->GetAbsVelocity().Length2D(); bool bSprintButtonPressed = ( mv->m_nButtons & IN_SPEED ) > 0; if( bSprintButtonPressed && ( mv->m_nButtons & IN_FORWARD ) && #if defined ( SDK_USE_PRONE ) !m_pSDKPlayer->m_Shared.IsProne() && #endif !m_pSDKPlayer->m_Shared.IsDucking() && flSpeedCheck > 80 ) { m_pSDKPlayer->SetSprinting( true ); } else { m_pSDKPlayer->SetSprinting( false ); } #endif // SDK_USE_SPRINTING // Get the movement angles. Vector vecForward, vecRight, vecUp; AngleVectors( mv->m_vecViewAngles, &vecForward, &vecRight, &vecUp ); vecForward.z = 0.0f; vecRight.z = 0.0f; VectorNormalize( vecForward ); VectorNormalize( vecRight ); // Copy movement amounts float flForwardMove = mv->m_flForwardMove; float flSideMove = mv->m_flSideMove; // Find the direction,velocity in the x,y plane. Vector vecWishDirection( ( ( vecForward.x * flForwardMove ) + ( vecRight.x * flSideMove ) ), ( ( vecForward.y * flForwardMove ) + ( vecRight.y * flSideMove ) ), 0.0f ); // Calculate the speed and direction of movement, then clamp the speed. float flWishSpeed = VectorNormalize( vecWishDirection ); flWishSpeed = clamp( flWishSpeed, 0.0f, mv->m_flMaxSpeed ); // Accelerate in the x,y plane. mv->m_vecVelocity.z = 0; Accelerate( vecWishDirection, flWishSpeed, sv_accelerate.GetFloat() ); Assert( mv->m_vecVelocity.z == 0.0f ); // Clamp the players speed in x,y. float flNewSpeed = VectorLength( mv->m_vecVelocity ); if ( flNewSpeed > mv->m_flMaxSpeed ) { float flScale = ( mv->m_flMaxSpeed / flNewSpeed ); mv->m_vecVelocity.x *= flScale; mv->m_vecVelocity.y *= flScale; } // Now reduce their backwards speed to some percent of max, if they are travelling backwards unless they are under some minimum if ( sdk_clamp_back_speed.GetFloat() < 1.0 && VectorLength( mv->m_vecVelocity ) > sdk_clamp_back_speed_min.GetFloat() ) { float flDot = DotProduct( vecForward, mv->m_vecVelocity ); // are we moving backwards at all? if ( flDot < 0 ) { Vector vecBackMove = vecForward * flDot; Vector vecRightMove = vecRight * DotProduct( vecRight, mv->m_vecVelocity ); // clamp the back move vector if it is faster than max float flBackSpeed = VectorLength( vecBackMove ); float flMaxBackSpeed = ( mv->m_flMaxSpeed * sdk_clamp_back_speed.GetFloat() ); if ( flBackSpeed > flMaxBackSpeed ) { vecBackMove *= flMaxBackSpeed / flBackSpeed; } // reassemble velocity mv->m_vecVelocity = vecBackMove + vecRightMove; } } // Add base velocity to the player's current velocity - base velocity = velocity from conveyors, etc. VectorAdd( mv->m_vecVelocity, player->GetBaseVelocity(), mv->m_vecVelocity ); // Calculate the current speed and return if we are not really moving. float flSpeed = VectorLength( mv->m_vecVelocity ); if ( flSpeed < 1.0f ) { // I didn't remove the base velocity here since it wasn't moving us in the first place. mv->m_vecVelocity.Init(); return; } // Calculate the destination. Vector vecDestination; vecDestination.x = mv->GetAbsOrigin().x + ( mv->m_vecVelocity.x * gpGlobals->frametime ); vecDestination.y = mv->GetAbsOrigin().y + ( mv->m_vecVelocity.y * gpGlobals->frametime ); vecDestination.z = mv->GetAbsOrigin().z; // Try moving to the destination. trace_t trace; TracePlayerBBox( mv->GetAbsOrigin(), vecDestination, PlayerSolidMask(), COLLISION_GROUP_PLAYER_MOVEMENT, trace ); if ( trace.fraction == 1.0f ) { // Made it to the destination (remove the base velocity). mv->SetAbsOrigin( trace.endpos ); VectorSubtract( mv->m_vecVelocity, player->GetBaseVelocity(), mv->m_vecVelocity ); // Save the wish velocity. mv->m_outWishVel += ( vecWishDirection * flWishSpeed ); // Try and keep the player on the ground. // NOTE YWB 7/5/07: Don't do this here, our version of CategorizePosition encompasses this test // StayOnGround(); return; } // Now try and do a step move. StepMove( vecDestination, trace ); // Remove base velocity. Vector baseVelocity = player->GetBaseVelocity(); VectorSubtract( mv->m_vecVelocity, baseVelocity, mv->m_vecVelocity ); // Save the wish velocity. mv->m_outWishVel += ( vecWishDirection * flWishSpeed ); // Try and keep the player on the ground. // NOTE YWB 7/5/07: Don't do this here, our version of CategorizePosition encompasses this test // StayOnGround(); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CTFGameMovement::WaterMove( void ) { int i; float wishspeed; Vector wishdir; Vector start, dest; Vector temp; trace_t pm; float speed, newspeed, addspeed, accelspeed; // Determine movement angles. Vector vecForward, vecRight, vecUp; AngleVectors( mv->m_vecViewAngles, &vecForward, &vecRight, &vecUp ); // Calculate the desired direction and speed. Vector vecWishVelocity; int iAxis; for ( iAxis = 0 ; iAxis < 3; ++iAxis ) { vecWishVelocity[iAxis] = ( vecForward[iAxis] * mv->m_flForwardMove ) + ( vecRight[iAxis] * mv->m_flSideMove ); } // Check for upward velocity (JUMP). if ( mv->m_nButtons & IN_JUMP ) { if ( player->GetWaterLevel() == WL_Eyes ) { vecWishVelocity[2] += mv->m_flClientMaxSpeed; } } // Sinking if not moving. else if ( !mv->m_flForwardMove && !mv->m_flSideMove && !mv->m_flUpMove ) { vecWishVelocity[2] -= 60; } // Move up based on view angle. else { vecWishVelocity[2] += mv->m_flUpMove; } // Copy it over and determine speed VectorCopy( vecWishVelocity, wishdir ); wishspeed = VectorNormalize( wishdir ); // Cap speed. if (wishspeed > mv->m_flMaxSpeed) { VectorScale( vecWishVelocity, mv->m_flMaxSpeed/wishspeed, vecWishVelocity ); wishspeed = mv->m_flMaxSpeed; } // Slow us down a bit. wishspeed *= 0.8; // Water friction VectorCopy( mv->m_vecVelocity, temp ); speed = VectorNormalize( temp ); if ( speed ) { newspeed = speed - gpGlobals->frametime * speed * sv_friction.GetFloat() * player->m_surfaceFriction; if ( newspeed < 0.1f ) { newspeed = 0; } VectorScale (mv->m_vecVelocity, newspeed/speed, mv->m_vecVelocity); } else { newspeed = 0; } // water acceleration if (wishspeed >= 0.1f) // old ! { addspeed = wishspeed - newspeed; if (addspeed > 0) { VectorNormalize(vecWishVelocity); accelspeed = sv_accelerate.GetFloat() * wishspeed * gpGlobals->frametime * player->m_surfaceFriction; if (accelspeed > addspeed) { accelspeed = addspeed; } for (i = 0; i < 3; i++) { float deltaSpeed = accelspeed * vecWishVelocity[i]; mv->m_vecVelocity[i] += deltaSpeed; mv->m_outWishVel[i] += deltaSpeed; } } } VectorAdd (mv->m_vecVelocity, player->GetBaseVelocity(), mv->m_vecVelocity); // Now move // assume it is a stair or a slope, so press down from stepheight above VectorMA (mv->GetAbsOrigin(), gpGlobals->frametime, mv->m_vecVelocity, dest); TracePlayerBBox( mv->GetAbsOrigin(), dest, PlayerSolidMask(), COLLISION_GROUP_PLAYER_MOVEMENT, pm ); if ( pm.fraction == 1.0f ) { VectorCopy( dest, start ); if ( player->m_Local.m_bAllowAutoMovement ) { start[2] += player->m_Local.m_flStepSize + 1; } TracePlayerBBox( start, dest, PlayerSolidMask(), COLLISION_GROUP_PLAYER_MOVEMENT, pm ); if (!pm.startsolid && !pm.allsolid) { #if 0 float stepDist = pm.endpos.z - mv->GetAbsOrigin().z; mv->m_outStepHeight += stepDist; // walked up the step, so just keep result and exit Vector vecNewWaterPoint; VectorCopy( m_vecWaterPoint, vecNewWaterPoint ); vecNewWaterPoint.z += ( dest.z - mv->GetAbsOrigin().z ); bool bOutOfWater = !( enginetrace->GetPointContents( vecNewWaterPoint ) & MASK_WATER ); if ( bOutOfWater && ( mv->m_vecVelocity.z > 0.0f ) && ( pm.fraction == 1.0f ) ) { // Check the waist level water positions. trace_t traceWater; UTIL_TraceLine( vecNewWaterPoint, m_vecWaterPoint, CONTENTS_WATER, player, COLLISION_GROUP_NONE, &traceWater ); if( traceWater.fraction < 1.0f ) { float flFraction = 1.0f - traceWater.fraction; // Vector vecSegment; // VectorSubtract( mv->GetAbsOrigin(), dest, vecSegment ); // VectorMA( mv->GetAbsOrigin(), flFraction, vecSegment, mv->GetAbsOrigin() ); float flZDiff = dest.z - mv->GetAbsOrigin().z; float flSetZ = mv->GetAbsOrigin().z + ( flFraction * flZDiff ); flSetZ -= 0.0325f; VectorCopy (pm.endpos, mv->GetAbsOrigin()); mv->GetAbsOrigin().z = flSetZ; VectorSubtract( mv->m_vecVelocity, player->GetBaseVelocity(), mv->m_vecVelocity ); mv->m_vecVelocity.z = 0.0f; } } else { VectorCopy (pm.endpos, mv->GetAbsOrigin()); VectorSubtract( mv->m_vecVelocity, player->GetBaseVelocity(), mv->m_vecVelocity ); } return; #endif float stepDist = pm.endpos.z - mv->GetAbsOrigin().z; mv->m_outStepHeight += stepDist; // walked up the step, so just keep result and exit mv->SetAbsOrigin( pm.endpos ); VectorSubtract( mv->m_vecVelocity, player->GetBaseVelocity(), mv->m_vecVelocity ); return; } // Try moving straight along out normal path. TryPlayerMove(); } else { if ( !player->GetGroundEntity() ) { TryPlayerMove(); VectorSubtract( mv->m_vecVelocity, player->GetBaseVelocity(), mv->m_vecVelocity ); return; } StepMove( dest, pm ); } VectorSubtract( mv->m_vecVelocity, player->GetBaseVelocity(), mv->m_vecVelocity ); }