Fix dynamic interaction problems caused by walkframe sequence movement

This commit is contained in:
ALLEN-PC\acj30 2024-01-03 13:31:38 -06:00
parent 869ec6d0dd
commit dc8fe6021d
2 changed files with 55 additions and 2 deletions

View File

@ -16142,6 +16142,7 @@ bool CAI_BaseNPC::InteractionCouldStart( CAI_BaseNPC *pOtherNPC, ScriptedNPCInte
if ( bDebug ) if ( bDebug )
{ {
NDebugOverlay::Box( vecPos, GetHullMins(), GetHullMaxs(), 255,0,0, 100, 1.0 ); NDebugOverlay::Box( vecPos, GetHullMins(), GetHullMaxs(), 255,0,0, 100, 1.0 );
NDebugOverlay::HorzArrow( GetAbsOrigin(), vecPos, 16.0f, 255, 0, 0, 255, true, 1.0f );
} }
return false; return false;
} }
@ -16149,7 +16150,39 @@ bool CAI_BaseNPC::InteractionCouldStart( CAI_BaseNPC *pOtherNPC, ScriptedNPCInte
{ {
//NDebugOverlay::Box( vecPos, GetHullMins(), GetHullMaxs(), 0,255,0, 100, 1.0 ); //NDebugOverlay::Box( vecPos, GetHullMins(), GetHullMaxs(), 0,255,0, 100, 1.0 );
NDebugOverlay::Axis( vecPos, angAngles, 20, true, 10.0 ); NDebugOverlay::Axis( vecPos, angAngles, 20, true, 1.0 );
}
}
else
{
// Instead, make sure we fit into where the sequence movement ends at
const char *pszSequence = GetScriptedNPCInteractionSequence( pInteraction, SNPCINT_SEQUENCE );
int nSeq = LookupSequence( pszSequence );
if ( pszSequence && nSeq != -1 )
{
Vector vecDeltaPos;
QAngle angDeltaAngles;
GetSequenceMovement( nSeq, 0.0f, 1.0f, vecDeltaPos, angDeltaAngles );
if (!vecDeltaPos.IsZero())
{
QAngle angInteraction = GetAbsAngles();
angInteraction[YAW] = m_flInteractionYaw;
Vector vecPos;
VectorRotate( vecDeltaPos, angInteraction, vecPos );
vecPos += GetAbsOrigin();
AI_TraceHull( vecPos, vecPos, GetHullMins(), GetHullMaxs(), MASK_SOLID, &traceFilter, &tr);
if ( tr.fraction != 1.0 )
{
if ( bDebug )
{
NDebugOverlay::Box( vecPos, GetHullMins(), GetHullMaxs(), 255,0,0, 100, 1.0 );
NDebugOverlay::HorzArrow( GetAbsOrigin(), vecPos, 16.0f, 255, 0, 0, 255, true, 1.0f );
}
return false;
}
}
} }
} }
#endif #endif

View File

@ -1396,11 +1396,31 @@ void CAI_ScriptedSequence::ModifyScriptedAutoMovement( Vector *vecNewPos )
} }
} }
VMatrix matInteractionPosition = m_matInteractionPosition;
#ifdef MAPBASE
// Account for our own sequence movement
pAnimating = m_hTargetEnt->GetBaseAnimating();
if (pAnimating)
{
Vector vecDeltaPos;
QAngle angDeltaAngles;
pAnimating->GetSequenceMovement( pAnimating->GetSequence(), 0.0f, pAnimating->GetCycle(), vecDeltaPos, angDeltaAngles );
if (!vecDeltaPos.IsZero())
{
VMatrix matLocalMovement;
matLocalMovement.SetupMatrixOrgAngles( vecDeltaPos, angDeltaAngles );
MatrixMultiply( m_matInteractionPosition, matLocalMovement, matInteractionPosition );
}
}
#endif
// We've been asked to maintain a specific position relative to the other NPC // We've been asked to maintain a specific position relative to the other NPC
// we're interacting with. Lerp towards the relative position. // we're interacting with. Lerp towards the relative position.
VMatrix matMeToWorld, matLocalToWorld; VMatrix matMeToWorld, matLocalToWorld;
matMeToWorld.SetupMatrixOrgAngles( vecRelativeOrigin, angRelativeAngles ); matMeToWorld.SetupMatrixOrgAngles( vecRelativeOrigin, angRelativeAngles );
MatrixMultiply( matMeToWorld, m_matInteractionPosition, matLocalToWorld ); MatrixMultiply( matMeToWorld, matInteractionPosition, matLocalToWorld );
// Get the desired NPC position in worldspace // Get the desired NPC position in worldspace
Vector vecOrigin; Vector vecOrigin;