MCPcopy Create free account
hub / github.com/JACoders/OpenJK / NPC_FacePosition

Function NPC_FacePosition

code/game/NPC_utils.cpp:1334–1394  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1332*/
1333
1334qboolean NPC_FacePosition( vec3_t position, qboolean doPitch )
1335{
1336 vec3_t muzzle;
1337 qboolean facing = qtrue;
1338
1339 //Get the positions
1340 if ( NPC->client && (NPC->client->NPC_class == CLASS_RANCOR || NPC->client->NPC_class == CLASS_WAMPA || NPC->client->NPC_class == CLASS_SAND_CREATURE) )
1341 {
1342 CalcEntitySpot( NPC, SPOT_ORIGIN, muzzle );
1343 muzzle[2] += NPC->maxs[2] * 0.75f;
1344 }
1345 else if ( NPC->client && NPC->client->NPC_class == CLASS_GALAKMECH )
1346 {
1347 CalcEntitySpot( NPC, SPOT_WEAPON, muzzle );
1348 }
1349 else
1350 {
1351 CalcEntitySpot( NPC, SPOT_HEAD_LEAN, muzzle );//SPOT_HEAD
1352 if ( NPC->client->NPC_class == CLASS_ROCKETTROOPER )
1353 {//*sigh*, look down more
1354 position[2] -= 32;
1355 }
1356 }
1357
1358 //Find the desired angles
1359 vec3_t angles;
1360
1361 GetAnglesForDirection( muzzle, position, angles );
1362
1363 NPCInfo->desiredYaw = AngleNormalize360( angles[YAW] );
1364 NPCInfo->desiredPitch = AngleNormalize360( angles[PITCH] );
1365
1366 if ( NPC->enemy && NPC->enemy->client && NPC->enemy->client->NPC_class == CLASS_ATST )
1367 {
1368 // FIXME: this is kind of dumb, but it was the easiest way to get it to look sort of ok
1369 NPCInfo->desiredYaw += Q_flrand( -5, 5 ) + sin( level.time * 0.004f ) * 7;
1370 NPCInfo->desiredPitch += Q_flrand( -2, 2 );
1371 }
1372 //Face that yaw
1373 NPC_UpdateAngles( qtrue, qtrue );
1374
1375 //Find the delta between our goal and our current facing
1376 float yawDelta = AngleNormalize360( NPCInfo->desiredYaw - ( SHORT2ANGLE( ucmd.angles[YAW] + client->ps.delta_angles[YAW] ) ) );
1377
1378 //See if we are facing properly
1379 if ( fabs( yawDelta ) > VALID_ATTACK_CONE )
1380 facing = qfalse;
1381
1382 if ( doPitch )
1383 {
1384 //Find the delta between our goal and our current facing
1385 float currentAngles = ( SHORT2ANGLE( ucmd.angles[PITCH] + client->ps.delta_angles[PITCH] ) );
1386 float pitchDelta = NPCInfo->desiredPitch - currentAngles;
1387
1388 //See if we are facing properly
1389 if ( fabs( pitchDelta ) > VALID_ATTACK_CONE )
1390 facing = qfalse;
1391 }

Callers 8

Boba_TacticsFunction · 0.70
Boba_FleeFunction · 0.70
NPC_JumpingFunction · 0.70
NPC_JumpBackingUpFunction · 0.70
Rancor_AttackBBrushFunction · 0.70
NPC_FaceEntityFunction · 0.70
ST_LookAroundFunction · 0.70

Calls 5

GetAnglesForDirectionFunction · 0.85
AngleNormalize360Function · 0.85
Q_flrandFunction · 0.85
CalcEntitySpotFunction · 0.70
NPC_UpdateAnglesFunction · 0.70

Tested by

no test coverage detected