Allow NPCs to face targets while parented

This commit is contained in:
ALLEN-PC\acj30 2025-02-09 10:37:44 -06:00 committed by Blixibon
parent dfc1e01e15
commit 985ebc0dbb
2 changed files with 14 additions and 14 deletions

View File

@ -3043,7 +3043,7 @@ void CAI_BaseNPC::SetHeadDirection( const Vector &vTargetPos, float flInterval)
//-------------------------------------- //--------------------------------------
// Set head yaw // Set head yaw
//-------------------------------------- //--------------------------------------
float flDesiredYaw = VecToYaw(vTargetPos - GetLocalOrigin()) - GetLocalAngles().y; float flDesiredYaw = VecToYaw(vTargetPos - GetAbsOrigin()) - GetAbsAngles().y;
if (flDesiredYaw > 180) if (flDesiredYaw > 180)
flDesiredYaw -= 360; flDesiredYaw -= 360;
if (flDesiredYaw < -180) if (flDesiredYaw < -180)
@ -8003,7 +8003,7 @@ void CAI_BaseNPC::NPCInit ( void )
SetGravity(1.0); // Don't change SetGravity(1.0); // Don't change
m_takedamage = DAMAGE_YES; m_takedamage = DAMAGE_YES;
GetMotor()->SetIdealYaw( GetLocalAngles().y ); GetMotor()->SetIdealYaw( GetAbsAngles().y );
m_iMaxHealth = m_iHealth; m_iMaxHealth = m_iHealth;
m_lifeState = LIFE_ALIVE; m_lifeState = LIFE_ALIVE;
SetIdealState( NPC_STATE_IDLE );// Assume npc will be idle, until proven otherwise SetIdealState( NPC_STATE_IDLE );// Assume npc will be idle, until proven otherwise
@ -9644,14 +9644,14 @@ float CAI_BaseNPC::CalcIdealYaw( const Vector &vecTarget )
vecProjection.x = -vecTarget.y; vecProjection.x = -vecTarget.y;
vecProjection.y = vecTarget.x; vecProjection.y = vecTarget.x;
return UTIL_VecToYaw( vecProjection - GetLocalOrigin() ); return UTIL_VecToYaw( vecProjection - GetAbsOrigin() );
} }
else if ( GetNavigator()->GetMovementActivity() == ACT_STRAFE_RIGHT ) else if ( GetNavigator()->GetMovementActivity() == ACT_STRAFE_RIGHT )
{ {
vecProjection.x = vecTarget.y; vecProjection.x = vecTarget.y;
vecProjection.y = vecTarget.x; vecProjection.y = vecTarget.x;
return UTIL_VecToYaw( vecProjection - GetLocalOrigin() ); return UTIL_VecToYaw( vecProjection - GetAbsOrigin() );
} }
#ifdef MAPBASE #ifdef MAPBASE
// Allow hint nodes to override the yaw without needing to control AI // Allow hint nodes to override the yaw without needing to control AI
@ -9662,7 +9662,7 @@ float CAI_BaseNPC::CalcIdealYaw( const Vector &vecTarget )
#endif #endif
else else
{ {
return UTIL_VecToYaw ( vecTarget - GetLocalOrigin() ); return UTIL_VecToYaw ( vecTarget - GetAbsOrigin() );
} }
} }
@ -9862,7 +9862,7 @@ void CAI_BaseNPC::HandleAnimEvent( animevent_t *pEvent )
//DevMsg( "Turned!\n" ); //DevMsg( "Turned!\n" );
SetIdealActivity( ACT_IDLE ); SetIdealActivity( ACT_IDLE );
Forget( bits_MEMORY_TURNING ); Forget( bits_MEMORY_TURNING );
SetBoneController( 0, GetLocalAngles().y ); SetBoneController( 0, GetAbsAngles().y );
IncrementInterpolationFrame(); IncrementInterpolationFrame();
break; break;
} }
@ -11141,7 +11141,7 @@ Vector CAI_BaseNPC::GetShootEnemyDir( const Vector &shootOrigin, bool bNoisy )
else else
{ {
Vector forward; Vector forward;
AngleVectors( GetLocalAngles(), &forward ); AngleVectors( GetAbsAngles(), &forward );
return forward; return forward;
} }
} }
@ -14179,7 +14179,7 @@ bool CAI_BaseNPC::OverrideMove( float flInterval )
float CAI_BaseNPC::VecToYaw( const Vector &vecDir ) float CAI_BaseNPC::VecToYaw( const Vector &vecDir )
{ {
if (vecDir.x == 0 && vecDir.y == 0 && vecDir.z == 0) if (vecDir.x == 0 && vecDir.y == 0 && vecDir.z == 0)
return GetLocalAngles().y; return GetAbsAngles().y;
return UTIL_VecToYaw( vecDir ); return UTIL_VecToYaw( vecDir );
} }

View File

@ -964,7 +964,7 @@ void CAI_BaseNPC::StartTurn( float flDeltaYaw )
{ {
float flCurrentYaw; float flCurrentYaw;
flCurrentYaw = UTIL_AngleMod( GetLocalAngles().y ); flCurrentYaw = UTIL_AngleMod( GetAbsAngles().y );
GetMotor()->SetIdealYaw( UTIL_AngleMod( flCurrentYaw + flDeltaYaw ) ); GetMotor()->SetIdealYaw( UTIL_AngleMod( flCurrentYaw + flDeltaYaw ) );
SetTurnActivity(); SetTurnActivity();
} }
@ -1157,7 +1157,7 @@ void CAI_BaseNPC::StartScriptMoveToTargetTask( int task )
{ {
TaskFail(FAIL_NO_TARGET); TaskFail(FAIL_NO_TARGET);
} }
else if ( (m_hTargetEnt->GetAbsOrigin() - GetLocalOrigin()).Length() < 1 ) else if ( (m_hTargetEnt->GetAbsOrigin() - GetAbsOrigin()).Length() < 1 )
{ {
TaskComplete(); TaskComplete();
} }
@ -1622,7 +1622,7 @@ void CAI_BaseNPC::StartTask( const Task_t *pTask )
break; break;
case TASK_SET_IDEAL_YAW_TO_CURRENT: case TASK_SET_IDEAL_YAW_TO_CURRENT:
GetMotor()->SetIdealYaw( UTIL_AngleMod( GetLocalAngles().y ) ); GetMotor()->SetIdealYaw( UTIL_AngleMod( GetAbsAngles().y ) );
TaskComplete(); TaskComplete();
break; break;
@ -1776,7 +1776,7 @@ void CAI_BaseNPC::StartTask( const Task_t *pTask )
{ {
TaskFail(FAIL_NO_TARGET); TaskFail(FAIL_NO_TARGET);
} }
else if ( (pTarget->GetAbsOrigin() - GetLocalOrigin()).Length() < 1 ) else if ( (pTarget->GetAbsOrigin() - GetAbsOrigin()).Length() < 1 )
{ {
TaskComplete(); TaskComplete();
} }
@ -3021,7 +3021,7 @@ void CAI_BaseNPC::StartTask( const Task_t *pTask )
{ {
if ( m_hTargetEnt != NULL ) if ( m_hTargetEnt != NULL )
{ {
GetMotor()->SetIdealYaw( UTIL_AngleMod( m_hTargetEnt->GetLocalAngles().y ) ); GetMotor()->SetIdealYaw( UTIL_AngleMod( m_hTargetEnt->GetAbsAngles().y ) );
} }
if ( m_scriptState != SCRIPT_CUSTOM_MOVE_TO_MARK ) if ( m_scriptState != SCRIPT_CUSTOM_MOVE_TO_MARK )
@ -3350,7 +3350,7 @@ void CAI_BaseNPC::RunTask( const Task_t *pTask )
pTarget = GetEnemy(); pTarget = GetEnemy();
if ( pTarget ) if ( pTarget )
{ {
GetMotor()->SetIdealYawAndUpdate( pTarget->GetAbsOrigin() - GetLocalOrigin() , AI_KEEP_YAW_SPEED ); GetMotor()->SetIdealYawAndUpdate( pTarget->GetAbsOrigin() - GetAbsOrigin(), AI_KEEP_YAW_SPEED );
} }
if ( IsActivityFinished() ) if ( IsActivityFinished() )