void CGravControllerPoint::DetachEntity( void ) { CBaseEntity *pEntity = m_attachedEntity; if ( pEntity ) { IPhysicsObject *pPhys = GetPhysObjFromPhysicsBone( pEntity, m_attachedPhysicsBone ); if ( pPhys ) { // on the odd chance that it's gone to sleep while under anti-gravity pPhys->Wake(); pPhys->SetDamping( NULL, &m_saveDamping ); pPhys->SetMass( m_saveMass ); } } m_attachedEntity = NULL; m_attachedPhysicsBone = 0; if ( physenv ) { physenv->DestroyMotionController( m_controller ); } m_controller = NULL; // UNDONE: Does this help the networking? m_targetPosition = vec3_origin; m_worldPosition = vec3_origin; }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- int CPhysBox::OnTakeDamage( const CTakeDamageInfo &info ) { // note: if motion is disabled, OnTakeDamage can't apply physics force int ret = BaseClass::OnTakeDamage( info ); // Check our health against the threshold: if( m_damageToEnableMotion > 0 && GetHealth() < m_damageToEnableMotion ) { // only do this once m_damageToEnableMotion = 0; IPhysicsObject *pPhysicsObject = VPhysicsGetObject(); if ( pPhysicsObject != NULL ) { pPhysicsObject->Wake(); pPhysicsObject->EnableMotion( true ); VPhysicsTakeDamage( info ); } } if ( info.GetInflictor() ) { m_OnDamaged.FireOutput( info.GetAttacker(), this ); } return ret; }
void CWeaponGravityGun::AttachObject( CBaseEntity *pObject, const Vector& start, const Vector &end, float distance ) { CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); if( !pOwner ) return; m_hObject = pObject; m_useDown = false; IPhysicsObject *pPhysics = pObject ? (pObject->VPhysicsGetObject()) : NULL; if ( pPhysics && pObject->GetMoveType() == MOVETYPE_VPHYSICS ) { m_distance = distance; Vector worldPosition; pObject->WorldToEntitySpace( end, &worldPosition ); m_worldPosition = worldPosition; m_gravCallback.AttachEntity( pOwner, pObject, pPhysics, pObject->GetAbsOrigin() ); m_originalObjectPosition = pObject->GetAbsOrigin(); pPhysics->Wake(); PhysSetGameFlags( pPhysics, FVPHYSICS_PLAYER_HELD ); #ifndef CLIENT_DLL Pickup_OnPhysGunPickup( pObject, pOwner ); #endif } else { m_hObject = NULL; } }
void CNPC_Zombine::DropGrenade( Vector vDir ) { if ( m_hGrenade == NULL ) return; m_hGrenade->SetParent( NULL ); m_hGrenade->SetOwnerEntity( NULL ); Vector vGunPos; QAngle angles; GetAttachment( "grenade_attachment", vGunPos, angles ); IPhysicsObject *pPhysObj = m_hGrenade->VPhysicsGetObject(); if ( pPhysObj == NULL ) { m_hGrenade->SetMoveType( MOVETYPE_VPHYSICS ); m_hGrenade->SetSolid( SOLID_VPHYSICS ); m_hGrenade->SetCollisionGroup( COLLISION_GROUP_WEAPON ); m_hGrenade->CreateVPhysics(); } if ( pPhysObj ) { pPhysObj->Wake(); pPhysObj->SetPosition( vGunPos, angles, true ); pPhysObj->ApplyForceCenter( vDir * 0.2f ); pPhysObj->RecheckCollisionFilter(); } m_hGrenade = NULL; }
//----------------------------------------------------------------------------- // Purpose: Input handler for waking up the cannister if it is sleeping. //----------------------------------------------------------------------------- void CPhysicsCannister::InputWake( inputdata_t &data ) { IPhysicsObject *pPhys = VPhysicsGetObject(); if ( pPhys != NULL ) { pPhys->Wake(); } }
//--------------------------------------------------------- // A different bounce behavior for the citizen-modified mine. Detonates at the top of its apex, // and does not attempt to track enemies. //--------------------------------------------------------- void CBounceBomb::CavernBounceThink() { SetNextThink( gpGlobals->curtime + 0.1 ); StudioFrameAdvance(); IPhysicsObject *pPhysicsObject = VPhysicsGetObject(); if ( pPhysicsObject != NULL ) { const float MINE_MAX_JUMP_HEIGHT = 78; // Figure out how much headroom the mine has, and hop to within a few inches of that. trace_t tr; UTIL_TraceLine( GetAbsOrigin(), GetAbsOrigin() + Vector( 0, 0, MINE_MAX_JUMP_HEIGHT ), MASK_SHOT, this, COLLISION_GROUP_INTERACTIVE, &tr ); float height; if( tr.m_pEnt && tr.m_pEnt->VPhysicsGetObject() ) { // Physics object resting on me. Jump as hard as allowed to try to knock it away. height = MINE_MAX_JUMP_HEIGHT; } else { height = tr.endpos.z - GetAbsOrigin().z; height -= BOUNCEBOMB_RADIUS; if ( height < 0.1 ) height = 0.1; } float time = sqrt( height / (0.5 * sv_gravity.GetFloat()) ); float velocity = sv_gravity.GetFloat() * time; // or you can just AddVelocity to the object instead of ApplyForce float force = velocity * pPhysicsObject->GetMass(); Vector up; GetVectors( NULL, NULL, &up ); pPhysicsObject->Wake(); pPhysicsObject->ApplyForceCenter( up * force ); if( m_hNearestNPC ) { Vector vecPredict = m_hNearestNPC->GetSmoothedVelocity(); pPhysicsObject->ApplyForceCenter( vecPredict * (pPhysicsObject->GetMass() * 0.65f) ); } pPhysicsObject->ApplyTorqueCenter( AngularImpulse( random->RandomFloat( 15, 40 ), random->RandomFloat( 15, 40 ), random->RandomFloat( 30, 60 ) ) ); EmitSound( "NPC_CombineMine.Hop" ); SetThink( &CBounceBomb::ExplodeThink ); SetNextThink( gpGlobals->curtime + 0.33f ); } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CPhysicsCannister::CannisterActivate( CBaseEntity *pActivator, const Vector &thrustOffset ) { // already active or spent if ( m_active || !m_thrustTime ) { return; } m_hLauncher = pActivator; Vector thrustDirection = CalcLocalThrust( thrustOffset ); m_onActivate.FireOutput( pActivator, this, 0 ); m_thruster.CalcThrust( m_thrustOrigin, thrustDirection, VPhysicsGetObject() ); m_pController = physenv->CreateMotionController( &m_thruster ); IPhysicsObject *pPhys = VPhysicsGetObject(); m_pController->AttachObject( pPhys, true ); // Make sure the object is simulated pPhys->Wake(); m_active = true; m_activateTime = gpGlobals->curtime; SetNextThink( gpGlobals->curtime + m_thrustTime ); SetThink( &CPhysicsCannister::BeginShutdownThink ); QAngle angles; VectorAngles( -thrustDirection, angles ); m_pJet = dynamic_cast<CSteamJet *>( CBaseEntity::Create( "env_steam", m_thrustOrigin, angles, this ) ); m_pJet->SetParent( this ); float extra = m_thruster.m_thrust * (1/5000.f); extra = clamp( extra, 0, 1 ); m_pJet->m_SpreadSpeed = 15 * m_thruster.m_thrust * 0.001; m_pJet->m_Speed = 128 + 100 * extra; m_pJet->m_StartSize = 10; m_pJet->m_EndSize = 25; m_pJet->m_Rate = 52 + (int)extra*20; m_pJet->m_JetLength = 64; m_pJet->m_clrRender = m_clrRender; m_pJet->Use( this, this, USE_ON, 1 ); if ( m_gasSound != NULL_STRING ) { CPASAttenuationFilter filter( this ); EmitSound_t ep; ep.m_nChannel = CHAN_ITEM; ep.m_pSoundName = STRING(m_gasSound); ep.m_flVolume = 1.0f; ep.m_SoundLevel = SNDLVL_NORM; EmitSound( filter, entindex(), ep ); } }
void CPhysMotor::TurnOn( void ) { CBaseEntity *pAttached = m_attachedObject; if ( !pAttached ) return; IPhysicsObject *pPhys = pAttached->VPhysicsGetObject(); if ( pPhys ) { pPhys->Wake(); SetNextThink( gpGlobals->curtime ); } }
void CHL2MPRules::ManageObjectRelocation( void ) { int iTotal = m_hRespawnableItemsAndWeapons.Count(); if ( iTotal > 0 ) { for ( int i = 0; i < iTotal; i++ ) { CBaseEntity *pObject = m_hRespawnableItemsAndWeapons[i].Get(); if ( pObject ) { Vector vSpawOrigin; QAngle vSpawnAngles; if ( GetObjectsOriginalParameters( pObject, vSpawOrigin, vSpawnAngles ) == true ) { float flDistanceFromSpawn = (pObject->GetAbsOrigin() - vSpawOrigin ).Length(); if ( flDistanceFromSpawn > WEAPON_MAX_DISTANCE_FROM_SPAWN ) { bool shouldReset = false; IPhysicsObject *pPhysics = pObject->VPhysicsGetObject(); if ( pPhysics ) { shouldReset = pPhysics->IsAsleep(); } else { shouldReset = (pObject->GetFlags() & FL_ONGROUND) ? true : false; } if ( shouldReset ) { pObject->Teleport( &vSpawOrigin, &vSpawnAngles, NULL ); pObject->EmitSound( "AlyxEmp.Charge" ); IPhysicsObject *pPhys = pObject->VPhysicsGetObject(); if ( pPhys ) { pPhys->Wake(); } } } } } } } }
void CNPC_Dog::CleanCatchAndThrow( bool bClearTimers ) { if ( m_hPhysicsEnt ) { if ( m_bHasObject == true ) { IPhysicsObject *pPhysObj = m_hPhysicsEnt->VPhysicsGetObject(); m_hPhysicsEnt->SetParent( NULL ); m_hPhysicsEnt->SetOwnerEntity( NULL ); Vector vGunPos; QAngle angGunAngles; GetAttachment( m_iPhysGunAttachment, vGunPos, angGunAngles ); if ( pPhysObj ) { pPhysObj->Wake(); pPhysObj->RemoveShadowController(); pPhysObj->SetPosition( vGunPos, angGunAngles, true ); } else { Warning( "CleanCatchAndThrow: m_hPhysicsEnt->VPhysicsGetObject == NULL!\n" ); } m_hPhysicsEnt->SetMoveType( (MoveType_t)m_iContainerMoveType ); if ( pPhysObj ) { pPhysObj->RecheckCollisionFilter(); } ClearBeams(); } m_hPhysicsEnt = NULL; } if ( bClearTimers == true ) { m_bDoCatchThrowBehavior = false; m_bDoWaitforObjectBehavior = false; m_flTimeToCatch = 0.0f; m_flNextSwat = 0.0f; SetCondition( COND_DOG_LOST_PHYSICS_ENTITY ); } }
void CGrabController::DetachEntity( void ) { CBaseEntity *pEntity = GetAttached(); if ( pEntity ) { IPhysicsObject *pPhys = pEntity->VPhysicsGetObject(); if ( pPhys ) { // on the odd chance that it's gone to sleep while under anti-gravity pPhys->Wake(); pPhys->SetDamping( NULL, &m_saveRotDamping ); PhysClearGameFlags( pPhys, FVPHYSICS_PLAYER_HELD ); } } m_attachedEntity = NULL; physenv->DestroyMotionController( m_controller ); m_controller = NULL; }
void CPhysForce::ForceOff( void ) { if ( !m_pController ) return; physenv->DestroyMotionController( m_pController ); m_pController = NULL; SetThink( NULL ); SetNextThink( TICK_NEVER_THINK ); IPhysicsObject *pPhys = NULL; if ( m_attachedObject ) { pPhys = m_attachedObject->VPhysicsGetObject(); if ( pPhys ) { pPhys->Wake(); } } }
void CPhysicsNPCSolver::Think() { bool finished = m_allowIntersection ? !IsIntersecting() : !CheckTouching(); if ( finished ) { UTIL_Remove(this); return; } if ( m_allowIntersection ) { IPhysicsObject *pObject = m_hEntity->VPhysicsGetObject(); if ( !pObject ) { UTIL_Remove(this); return; } pObject->Wake(); } ResetCancelTime(); }
void CWeaponGravityGun::AttachObject( CBaseEntity *pObject, const Vector& start, const Vector &end, float distance ) { m_hObject = pObject; m_useDown = false; IPhysicsObject *pPhysics = pObject ? (pObject->VPhysicsGetObject()) : NULL; if ( pPhysics && pObject->GetMoveType() == MOVETYPE_VPHYSICS ) { m_distance = distance; m_gravCallback.AttachEntity( pObject, pPhysics, end ); float mass = pPhysics->GetMass(); Msg( "Object mass: %.2f lbs (%.2f kg)\n", kg2lbs(mass), mass ); float vel = phys_gunvel.GetFloat(); if ( mass > phys_gunmass.GetFloat() ) { vel = (vel*phys_gunmass.GetFloat())/mass; } m_gravCallback.SetMaxVelocity( vel ); // Msg( "Object mass: %.2f lbs (%.2f kg) %f %f %f\n", kg2lbs(mass), mass, pObject->GetAbsOrigin().x, pObject->GetAbsOrigin().y, pObject->GetAbsOrigin().z ); // Msg( "ANG: %f %f %f\n", pObject->GetAbsAngles().x, pObject->GetAbsAngles().y, pObject->GetAbsAngles().z ); m_originalObjectPosition = pObject->GetAbsOrigin(); m_pelletAttract = -1; m_pelletHeld = -1; pPhysics->Wake(); SortPelletsForObject( pObject ); CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); if( pOwner ) { Pickup_OnPhysGunPickup( pObject, pOwner ); } } else { m_hObject = NULL; } }
void SetTargetPosition( const Vector &target, const QAngle &targetOrientation ) { m_shadow.targetPosition = target; m_shadow.targetRotation = targetOrientation; m_timeToArrive = gpGlobals->frametime; CBaseEntity *pAttached = m_attachedEntity; if ( pAttached ) { IPhysicsObject *pObj = GetPhysObjFromPhysicsBone( pAttached, m_attachedPhysicsBone ); if ( pObj != NULL ) { pObj->Wake(); } else { DetachEntity(); } } }
void CGrabController::SetTargetPosition( const Vector &target, const QAngle &targetOrientation ) { m_shadow.targetPosition = target; m_shadow.targetRotation = targetOrientation; m_timeToArrive = gpGlobals->frametime; CBaseEntity *pAttached = GetAttached(); if ( pAttached ) { IPhysicsObject *pObj = pAttached->VPhysicsGetObject(); if ( pObj != NULL ) { pObj->Wake(); } else { DetachEntity( false ); } } }
void CGrabController::DetachEntity( bool bClearVelocity ) { Assert(!PhysIsInCallback()); CBaseEntity *pEntity = GetAttached(); if ( pEntity ) { // Restore the LS blocking state pEntity->SetBlocksLOS( m_bCarriedEntityBlocksLOS ); IPhysicsObject *pList[VPHYSICS_MAX_OBJECT_LIST_COUNT]; int count = pEntity->VPhysicsGetObjectList( pList, ARRAYSIZE(pList) ); for ( int i = 0; i < count; i++ ) { IPhysicsObject *pPhys = pList[i]; if ( !pPhys ) continue; // on the odd chance that it's gone to sleep while under anti-gravity pPhys->EnableDrag( true ); pPhys->Wake(); pPhys->SetMass( m_savedMass[i] ); pPhys->SetDamping( NULL, &m_savedRotDamping[i] ); PhysClearGameFlags( pPhys, FVPHYSICS_PLAYER_HELD ); if ( bClearVelocity ) { PhysForceClearVelocity( pPhys ); } else { ClampPhysicsVelocity( pPhys, player_walkspeed.GetFloat() * 1.5f, 2.0f * 360.0f ); } } } m_attachedEntity = NULL; physenv->DestroyMotionController( m_controller ); m_controller = NULL; }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- bool CTriggerPortalCleanser::TransferPhysicsObject( CBaseEntity *pFrom, CBaseEntity *pTo, bool wakeUp ) { IPhysicsObject *pVPhysics = pFrom->VPhysicsGetObject(); if ( !pVPhysics || pVPhysics->IsStatic() ) return false; Vector vecVelocity, vecAngular; pVPhysics->GetVelocity( &vecVelocity, &vecAngular ); // clear out the pointer so it won't get deleted pFrom->VPhysicsSwapObject( NULL ); // remove any AI behavior bound to it pVPhysics->RemoveShadowController(); // transfer to the new owner pTo->VPhysicsSetObject( pVPhysics ); pVPhysics->SetGameData( (void *)pTo ); pTo->VPhysicsUpdate( pVPhysics ); // may have been temporarily disabled by the old object pVPhysics->EnableMotion( true ); pVPhysics->EnableGravity( false ); // Slow down and push up the object. vecVelocity /= 2; vecAngular /= 2; vecVelocity.z += 10; pVPhysics->SetVelocity( &vecVelocity, &vecAngular ); // Update for the new entity solid type pVPhysics->RecheckCollisionFilter(); if ( wakeUp ) { pVPhysics->Wake(); } return true; }
void CTFGrenadeNailProjectile::StartEmittingNails( void ) { // 0.4 seconds later, emit nails IPhysicsObject *pPhysicsObject = VPhysicsGetObject(); if ( pPhysicsObject ) { m_pMotionController = physenv->CreateMotionController( &m_GrenadeController ); m_pMotionController->AttachObject( pPhysicsObject, true ); pPhysicsObject->EnableGravity( false ); pPhysicsObject->Wake(); } QAngle ang(0,0,0); Vector pos = GetAbsOrigin(); pos.z += 32; m_GrenadeController.SetDesiredPosAndOrientation( pos, ang ); m_flNailAngle = 0; m_iNumNailBurstsLeft = 40; int animDesired = SelectWeightedSequence( ACT_RANGE_ATTACK1 ); ResetSequence( animDesired ); SetPlaybackRate( 1.0 ); Vector soundPosition = GetAbsOrigin() + Vector( 0, 0, 5 ); CPASAttenuationFilter filter( soundPosition ); EmitSound( filter, entindex(), "Weapon_Grenade_Nail.Launch" ); #ifdef GAME_DLL SetThink( &CTFGrenadeNailProjectile::EmitNails ); SetNextThink( gpGlobals->curtime + 0.4 ); #endif }
void CPhysForce::ActivateForce( void ) { BaseClass::Activate(); IPhysicsObject *pPhys = NULL; if ( m_attachedObject ) { pPhys = m_attachedObject->VPhysicsGetObject(); } if ( !pPhys ) return; Vector linear; AngularImpulse angular; SetupForces( pPhys, linear, angular ); m_integrator.SetConstantForce( linear, angular ); m_pController = physenv->CreateMotionController( &m_integrator ); m_pController->AttachObject( pPhys ); // Make sure the object is simulated pPhys->Wake(); }
void CWeaponGravityGun::EffectUpdate( void ) { Vector start, forward, right; trace_t tr; CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); if ( !pOwner ) return; pOwner->EyeVectors( &forward, &right, NULL ); start = pOwner->Weapon_ShootPosition(); TraceLine( &tr ); Vector end = tr.endpos; float distance = tr.fraction * 4096; if ( m_hObject == NULL && tr.DidHitNonWorldEntity() ) { CBaseEntity *pEntity = tr.m_pEnt; AttachObject( pEntity, GetPhysObjFromPhysicsBone( pEntity, tr.physicsbone ), tr.physicsbone, start, tr.endpos, distance ); } // Add the incremental player yaw to the target transform QAngle angles = m_gravCallback.TransformAnglesFromPlayerSpace( m_gravCallback.m_targetRotation, pOwner ); CBaseEntity *pObject = m_hObject; if ( pObject ) { if ( m_useDown ) { if ( pOwner->m_afButtonPressed & IN_USE ) { m_useDown = false; } } else { if ( pOwner->m_afButtonPressed & IN_USE ) { m_useDown = true; } } if ( m_useDown ) { #ifndef CLIENT_DLL pOwner->SetPhysicsFlag( PFLAG_DIROVERRIDE, true ); #endif if ( pOwner->m_nButtons & IN_FORWARD ) { m_distance = Approach( 1024, m_distance, gpGlobals->frametime * 100 ); } if ( pOwner->m_nButtons & IN_BACK ) { m_distance = Approach( 40, m_distance, gpGlobals->frametime * 100 ); } } if ( pOwner->m_nButtons & IN_WEAPON1 ) { m_distance = Approach( 1024, m_distance, m_distance * 0.1 ); } if ( pOwner->m_nButtons & IN_WEAPON2 ) { m_distance = Approach( 40, m_distance, m_distance * 0.1 ); } IPhysicsObject *pPhys = GetPhysObjFromPhysicsBone( pObject, m_physicsBone ); if ( pPhys ) { if ( pPhys->IsAsleep() ) { // on the odd chance that it's gone to sleep while under anti-gravity pPhys->Wake(); } Vector newPosition = start + forward * m_distance; Vector offset; pPhys->LocalToWorld( &offset, m_worldPosition ); Vector vecOrigin; pPhys->GetPosition( &vecOrigin, NULL ); m_gravCallback.SetTargetPosition( newPosition + (vecOrigin - offset), angles ); Vector dir = (newPosition - pObject->GetLocalOrigin()); m_movementLength = dir.Length(); } } else { m_targetPosition = end; //m_gravCallback.SetTargetPosition( end, m_gravCallback.m_targetRotation ); } }
void CWeaponGravityGun::EffectUpdate( void ) { Vector start, forward, right; trace_t tr; CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); if ( !pOwner ) return; pOwner->EyeVectors( &forward, &right, NULL ); start = pOwner->Weapon_ShootPosition(); TraceLine( &tr ); Vector end = tr.endpos; float distance = tr.fraction * 4096; if ( tr.fraction != 1 ) { // too close to the player, drop the object if ( distance < 36 ) { DetachObject(); return; } } if ( m_hObject == NULL && tr.DidHitNonWorldEntity() ) { CBaseEntity *pEntity = tr.m_pEnt; AttachObject( pEntity, start, tr.endpos, distance ); m_lastYaw = pOwner->EyeAngles().y; } // Add the incremental player yaw to the target transform matrix3x4_t curMatrix, incMatrix, nextMatrix; AngleMatrix( m_gravCallback.m_targetRotation, curMatrix ); AngleMatrix( QAngle(0,pOwner->EyeAngles().y - m_lastYaw,0), incMatrix ); ConcatTransforms( incMatrix, curMatrix, nextMatrix ); MatrixAngles( nextMatrix, m_gravCallback.m_targetRotation ); m_lastYaw = pOwner->EyeAngles().y; CBaseEntity *pObject = m_hObject; if ( pObject ) { if ( m_useDown ) { if ( pOwner->m_afButtonPressed & IN_USE ) { m_useDown = false; } } else { if ( pOwner->m_afButtonPressed & IN_USE ) { m_useDown = true; } } if ( m_useDown ) { #ifndef CLIENT_DLL pOwner->SetPhysicsFlag( PFLAG_DIROVERRIDE, true ); #endif if ( pOwner->m_nButtons & IN_FORWARD ) { m_distance = Approach( 1024, m_distance, gpGlobals->frametime * 100 ); } if ( pOwner->m_nButtons & IN_BACK ) { m_distance = Approach( 40, m_distance, gpGlobals->frametime * 100 ); } } if ( pOwner->m_nButtons & IN_WEAPON1 ) { m_distance = Approach( 1024, m_distance, m_distance * 0.1 ); #ifdef CLIENT_DLL if ( gpGlobals->maxClients > 1 ) { gHUD.m_bSkipClear = false; } #endif } if ( pOwner->m_nButtons & IN_WEAPON2 ) { m_distance = Approach( 40, m_distance, m_distance * 0.1 ); #ifdef CLIENT_DLL if ( gpGlobals->maxClients > 1 ) { gHUD.m_bSkipClear = false; } #endif } IPhysicsObject *pPhys = pObject->VPhysicsGetObject(); if ( pPhys && pPhys->IsAsleep() ) { // on the odd chance that it's gone to sleep while under anti-gravity pPhys->Wake(); } Vector newPosition = start + forward * m_distance; Vector offset; pObject->EntityToWorldSpace( m_worldPosition, &offset ); m_gravCallback.SetTargetPosition( newPosition + (pObject->GetAbsOrigin() - offset), m_gravCallback.m_targetRotation ); Vector dir = (newPosition - pObject->GetLocalOrigin()); m_movementLength = dir.Length(); } else { m_targetPosition = end; //m_gravCallback.SetTargetPosition( end, m_gravCallback.m_targetRotation ); } }
void CNPC_Dog::ThrowObject( const char *pAttachmentName ) { if ( m_hPhysicsEnt ) { m_bHasObject = false; IPhysicsObject *pPhysObj = m_hPhysicsEnt->VPhysicsGetObject(); if ( pPhysObj ) { Vector vGunPos; QAngle angGunAngles; AngularImpulse angVelocity = RandomAngularImpulse( -250 , -250 ) / pPhysObj->GetMass(); InvalidateBoneCache(); int iAttachment = LookupAttachment( pAttachmentName ); if ( iAttachment == 0 ) iAttachment = m_iPhysGunAttachment; GetAttachment( iAttachment, vGunPos, angGunAngles ); pPhysObj->Wake(); if ( pPhysObj->GetShadowController() ) { m_hPhysicsEnt->SetParent( NULL ); m_hPhysicsEnt->SetMoveType( (MoveType_t)m_iContainerMoveType ); m_hPhysicsEnt->SetOwnerEntity( this ); pPhysObj->RemoveShadowController(); pPhysObj->SetPosition( m_hPhysicsEnt->GetLocalOrigin(), m_hPhysicsEnt->GetLocalAngles(), true ); pPhysObj->RecheckCollisionFilter(); pPhysObj->RecheckContactPoints(); } if ( m_hThrowTarget == NULL ) #ifdef SecobMod__Enable_Fixed_Multiplayer_AI m_hThrowTarget = UTIL_GetNearestVisiblePlayer(this); #else m_hThrowTarget = AI_GetSinglePlayer(); #endif //SecobMod__Enable_Fixed_Multiplayer_AI Vector vThrowDirection; if ( m_hThrowTarget ) { Vector vThrowOrigin = m_hThrowTarget->GetAbsOrigin(); if ( m_hThrowTarget->IsPlayer() ) vThrowOrigin = vThrowOrigin + Vector( random->RandomFloat( -128, 128 ), random->RandomFloat( -128, 128 ), 0 ); Vector vecToss = VecCheckToss( this, vGunPos, vThrowOrigin, m_flThrowArcModifier, 1.0f, true ); if( vecToss == vec3_origin ) { // Fix up an impossible throw so dog will at least toss the box in the target's general direction instead of dropping it. // Also toss it up in the air so it will fall down and break. (Just throw the box up at a 45 degree angle) Vector forward, up; GetVectors( &forward, NULL, &up ); vecToss = forward + up; VectorNormalize( vecToss ); vecToss *= pPhysObj->GetMass() * 30.0f; } vThrowDirection = vecToss + ( m_hThrowTarget->GetSmoothedVelocity() / 2 ); Vector vLinearDrag; Vector unitVel = vThrowDirection; VectorNormalize( unitVel ); float flTest = 1000 / vThrowDirection.Length(); float flDrag = pPhysObj->CalculateLinearDrag( vThrowDirection ); vThrowDirection = vThrowDirection + ( unitVel * ( flDrag * flDrag ) ) / flTest; pPhysObj->SetVelocity( &vThrowDirection, &angVelocity ); m_flTimeToCatch = gpGlobals->curtime + dog_max_wait_time.GetFloat(); //Don't start pulling until the object is away from me. //We base the time on the throw velocity. m_flTimeToPull = gpGlobals->curtime + ( 1000 / vThrowDirection.Length() ); } //Fire Output! m_OnThrow.FireOutput( this, this ); ClearBeams(); if ( m_bBeamEffects == true ) { EmitSound( "Weapon_PhysCannon.Launch" ); CBeam *pBeam = CBeam::BeamCreate( "sprites/orangelight1.vmt", 1.8 ); if ( pBeam != NULL ) { pBeam->PointEntInit( m_hPhysicsEnt->WorldSpaceCenter(), this ); pBeam->SetEndAttachment( m_iPhysGunAttachment ); pBeam->SetWidth( 6.4 ); pBeam->SetEndWidth( 12.8 ); pBeam->SetBrightness( 255 ); pBeam->SetColor( 255, 255, 255 ); pBeam->LiveForTime( 0.2f ); pBeam->RelinkBeam(); pBeam->SetNoise( 2 ); } Vector shotDir = ( m_hPhysicsEnt->WorldSpaceCenter() - vGunPos ); VectorNormalize( shotDir ); CPVSFilter filter( m_hPhysicsEnt->WorldSpaceCenter() ); te->GaussExplosion( filter, 0.0f, m_hPhysicsEnt->WorldSpaceCenter() - ( shotDir * 4.0f ), RandomVector(-1.0f, 1.0f), 0 ); } } } }
void CSDKPlayer::PhysObjectWake() { IPhysicsObject *pObj = VPhysicsGetObject(); if ( pObj ) pObj->Wake(); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CASWEnvShake::ApplyShake( ShakeCommand_t command ) { if ( !HasSpawnFlags( SF_ASW_SHAKE_NO_VIEW ) ) { bool air = (GetSpawnFlags() & SF_ASW_SHAKE_INAIR) ? true : false; UTIL_ASW_ScreenShake( GetAbsOrigin(), Amplitude(), Frequency(), Duration(), Radius(), command, air ); } if ( GetSpawnFlags() & SF_ASW_SHAKE_ROPES ) { CRopeKeyframe::ShakeRopes( GetAbsOrigin(), Radius(), Frequency() ); } if ( GetSpawnFlags() & SF_ASW_SHAKE_PHYSICS ) { if ( !m_pShakeController ) { m_pShakeController = physenv->CreateMotionController( &m_shakeCallback ); } // do physics shake switch( command ) { case SHAKE_START: { m_stopTime = gpGlobals->curtime + Duration(); m_nextShake = 0; m_pShakeController->ClearObjects(); SetNextThink( gpGlobals->curtime ); m_currentAmp = Amplitude(); CBaseEntity *list[1024]; float radius = Radius(); // probably checked "Shake Everywhere" do a big radius if ( !radius ) { radius = MAX_COORD_INTEGER; } Vector extents = Vector(radius, radius, radius); Vector mins = GetAbsOrigin() - extents; Vector maxs = GetAbsOrigin() + extents; int count = UTIL_EntitiesInBox( list, 1024, mins, maxs, 0 ); for ( int i = 0; i < count; i++ ) { // // Only shake physics entities that players can see. This is one frame out of date // so it's possible that we could miss objects if a player changed PVS this frame. // if ( ( list[i]->GetMoveType() == MOVETYPE_VPHYSICS ) ) { IPhysicsObject *pPhys = list[i]->VPhysicsGetObject(); if ( pPhys && pPhys->IsMoveable() ) { m_pShakeController->AttachObject( pPhys, false ); pPhys->Wake(); } } } } break; case SHAKE_STOP: m_pShakeController->ClearObjects(); break; case SHAKE_AMPLITUDE: m_currentAmp = Amplitude(); case SHAKE_FREQUENCY: m_pShakeController->WakeObjects(); break; } } }