Skip to content

Commit 985ebc0

Browse files
committed
Allow NPCs to face targets while parented
1 parent dfc1e01 commit 985ebc0

2 files changed

Lines changed: 14 additions & 14 deletions

File tree

sp/src/game/server/ai_basenpc.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3043,7 +3043,7 @@ void CAI_BaseNPC::SetHeadDirection( const Vector &vTargetPos, float flInterval)
30433043
//--------------------------------------
30443044
// Set head yaw
30453045
//--------------------------------------
3046-
float flDesiredYaw = VecToYaw(vTargetPos - GetLocalOrigin()) - GetLocalAngles().y;
3046+
float flDesiredYaw = VecToYaw(vTargetPos - GetAbsOrigin()) - GetAbsAngles().y;
30473047
if (flDesiredYaw > 180)
30483048
flDesiredYaw -= 360;
30493049
if (flDesiredYaw < -180)
@@ -8003,7 +8003,7 @@ void CAI_BaseNPC::NPCInit ( void )
80038003

80048004
SetGravity(1.0); // Don't change
80058005
m_takedamage = DAMAGE_YES;
8006-
GetMotor()->SetIdealYaw( GetLocalAngles().y );
8006+
GetMotor()->SetIdealYaw( GetAbsAngles().y );
80078007
m_iMaxHealth = m_iHealth;
80088008
m_lifeState = LIFE_ALIVE;
80098009
SetIdealState( NPC_STATE_IDLE );// Assume npc will be idle, until proven otherwise
@@ -9644,14 +9644,14 @@ float CAI_BaseNPC::CalcIdealYaw( const Vector &vecTarget )
96449644
vecProjection.x = -vecTarget.y;
96459645
vecProjection.y = vecTarget.x;
96469646

9647-
return UTIL_VecToYaw( vecProjection - GetLocalOrigin() );
9647+
return UTIL_VecToYaw( vecProjection - GetAbsOrigin() );
96489648
}
96499649
else if ( GetNavigator()->GetMovementActivity() == ACT_STRAFE_RIGHT )
96509650
{
96519651
vecProjection.x = vecTarget.y;
96529652
vecProjection.y = vecTarget.x;
96539653

9654-
return UTIL_VecToYaw( vecProjection - GetLocalOrigin() );
9654+
return UTIL_VecToYaw( vecProjection - GetAbsOrigin() );
96559655
}
96569656
#ifdef MAPBASE
96579657
// Allow hint nodes to override the yaw without needing to control AI
@@ -9662,7 +9662,7 @@ float CAI_BaseNPC::CalcIdealYaw( const Vector &vecTarget )
96629662
#endif
96639663
else
96649664
{
9665-
return UTIL_VecToYaw ( vecTarget - GetLocalOrigin() );
9665+
return UTIL_VecToYaw ( vecTarget - GetAbsOrigin() );
96669666
}
96679667
}
96689668

@@ -9862,7 +9862,7 @@ void CAI_BaseNPC::HandleAnimEvent( animevent_t *pEvent )
98629862
//DevMsg( "Turned!\n" );
98639863
SetIdealActivity( ACT_IDLE );
98649864
Forget( bits_MEMORY_TURNING );
9865-
SetBoneController( 0, GetLocalAngles().y );
9865+
SetBoneController( 0, GetAbsAngles().y );
98669866
IncrementInterpolationFrame();
98679867
break;
98689868
}
@@ -11141,7 +11141,7 @@ Vector CAI_BaseNPC::GetShootEnemyDir( const Vector &shootOrigin, bool bNoisy )
1114111141
else
1114211142
{
1114311143
Vector forward;
11144-
AngleVectors( GetLocalAngles(), &forward );
11144+
AngleVectors( GetAbsAngles(), &forward );
1114511145
return forward;
1114611146
}
1114711147
}
@@ -14179,7 +14179,7 @@ bool CAI_BaseNPC::OverrideMove( float flInterval )
1417914179
float CAI_BaseNPC::VecToYaw( const Vector &vecDir )
1418014180
{
1418114181
if (vecDir.x == 0 && vecDir.y == 0 && vecDir.z == 0)
14182-
return GetLocalAngles().y;
14182+
return GetAbsAngles().y;
1418314183

1418414184
return UTIL_VecToYaw( vecDir );
1418514185
}

sp/src/game/server/ai_basenpc_schedule.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ void CAI_BaseNPC::StartTurn( float flDeltaYaw )
964964
{
965965
float flCurrentYaw;
966966

967-
flCurrentYaw = UTIL_AngleMod( GetLocalAngles().y );
967+
flCurrentYaw = UTIL_AngleMod( GetAbsAngles().y );
968968
GetMotor()->SetIdealYaw( UTIL_AngleMod( flCurrentYaw + flDeltaYaw ) );
969969
SetTurnActivity();
970970
}
@@ -1157,7 +1157,7 @@ void CAI_BaseNPC::StartScriptMoveToTargetTask( int task )
11571157
{
11581158
TaskFail(FAIL_NO_TARGET);
11591159
}
1160-
else if ( (m_hTargetEnt->GetAbsOrigin() - GetLocalOrigin()).Length() < 1 )
1160+
else if ( (m_hTargetEnt->GetAbsOrigin() - GetAbsOrigin()).Length() < 1 )
11611161
{
11621162
TaskComplete();
11631163
}
@@ -1622,7 +1622,7 @@ void CAI_BaseNPC::StartTask( const Task_t *pTask )
16221622
break;
16231623

16241624
case TASK_SET_IDEAL_YAW_TO_CURRENT:
1625-
GetMotor()->SetIdealYaw( UTIL_AngleMod( GetLocalAngles().y ) );
1625+
GetMotor()->SetIdealYaw( UTIL_AngleMod( GetAbsAngles().y ) );
16261626
TaskComplete();
16271627
break;
16281628

@@ -1776,7 +1776,7 @@ void CAI_BaseNPC::StartTask( const Task_t *pTask )
17761776
{
17771777
TaskFail(FAIL_NO_TARGET);
17781778
}
1779-
else if ( (pTarget->GetAbsOrigin() - GetLocalOrigin()).Length() < 1 )
1779+
else if ( (pTarget->GetAbsOrigin() - GetAbsOrigin()).Length() < 1 )
17801780
{
17811781
TaskComplete();
17821782
}
@@ -3021,7 +3021,7 @@ void CAI_BaseNPC::StartTask( const Task_t *pTask )
30213021
{
30223022
if ( m_hTargetEnt != NULL )
30233023
{
3024-
GetMotor()->SetIdealYaw( UTIL_AngleMod( m_hTargetEnt->GetLocalAngles().y ) );
3024+
GetMotor()->SetIdealYaw( UTIL_AngleMod( m_hTargetEnt->GetAbsAngles().y ) );
30253025
}
30263026

30273027
if ( m_scriptState != SCRIPT_CUSTOM_MOVE_TO_MARK )
@@ -3350,7 +3350,7 @@ void CAI_BaseNPC::RunTask( const Task_t *pTask )
33503350
pTarget = GetEnemy();
33513351
if ( pTarget )
33523352
{
3353-
GetMotor()->SetIdealYawAndUpdate( pTarget->GetAbsOrigin() - GetLocalOrigin() , AI_KEEP_YAW_SPEED );
3353+
GetMotor()->SetIdealYawAndUpdate( pTarget->GetAbsOrigin() - GetAbsOrigin(), AI_KEEP_YAW_SPEED );
33543354
}
33553355

33563356
if ( IsActivityFinished() )

0 commit comments

Comments
 (0)