Это урезанный код краба собственно его AI :
//-----------------------------------------------------------------------------
// Animation events.
//-----------------------------------------------------------------------------
int AE_HEADCRAB_JUMPATTACK;
int AE_HEADCRAB_JUMP_TELEGRAPH;
class CSDKHeadcrab : public CAI_BaseNPC
{
DECLARE_CLASS( CSDKHeadcrab, CAI_BaseNPC );
public:
void Spawn( void );
void Precache( void );
virtual int TranslateSchedule( int scheduleType );
virtual Activity NPC_TranslateActivity( Activity eNewActivity );
void HandleAnimEvent( animevent_t *pEvent );
DEFINE_CUSTOM_AI; // set this class up, so it can do custom AI interaction,
// in our case we only declare some animation events
DECLARE_DATADESC();
};
// you can refer to this critter as sdk_headcrab in Hammer or the console
LINK_ENTITY_TO_CLASS( sdk_headcrab, CSDKHeadcrab );
// no additinal data
BEGIN_DATADESC( CSDKHeadcrab )
END_DATADESC()
// Name of our entity's model
#define ENTITY_MODEL "models/headcrabclassic.mdl"
//-----------------------------------------------------------------------------
// Purpose: Precache assets used by the entity
//-----------------------------------------------------------------------------
void CSDKHeadcrab::Precache( void )
{
// we ignore all the sounds for now
PrecacheModel( ENTITY_MODEL );
BaseClass::Precache();
}
//-----------------------------------------------------------------------------
// Purpose: Sets up the entity's initial state
//-----------------------------------------------------------------------------
void CSDKHeadcrab::Spawn( void )
{
Precache(); // precache resources
SetModel( ENTITY_MODEL ); // set the display model
BaseClass::Spawn(); // init CAI_BaseNPC's member vars
m_iHealth = 100.0; // set health of your crab; you'll want to make this a convar
SetHullType(HULL_TINY);
SetHullSizeNormal();
SetSolid( SOLID_BBOX );
// we don't want to allow others to stand on this critter
AddSolidFlags( FSOLID_NOT_STANDABLE );
SetMoveType( MOVETYPE_STEP );
// have to look into this, the original crab has it's own collision
SetCollisionGroup( COLLISION_GROUP_NPC );
// model defined in hl2 specific code
SetViewOffset( Vector(6, 0, 11) ) ; // Position of the eyes relative to NPC's origin.
SetBloodColor( BLOOD_COLOR_GREEN ); // guess ;-)
m_flFieldOfView = 0.5;
m_NPCState = NPC_STATE_NONE;
CapabilitiesClear();
// crab can move around and start melee attack
CapabilitiesAdd( bits_CAP_MOVE_GROUND | bits_CAP_INNATE_MELEE_ATTACK1 ); //может здесь чего не так ?
NPCInit(); // initialize our NPC
// Crab hates player, set to D_FR to see it run away from player
AddClassRelationship( CLASS_PLAYER, D_HT, 0 );
}
//-----------------------------------------------------------------------------
// Purpose: Override schedules
//
//-----------------------------------------------------------------------------
int CSDKHeadcrab::TranslateSchedule( int scheduleType )
{
switch ( scheduleType )
{
case SCHED_IDLE_STAND: // make the crab walk around instead of just standing there idly
return SCHED_PATROL_WALK;
break;
default:
return BaseClass::TranslateSchedule( scheduleType );
break;
}
}
//-----------------------------------------------------------------------------
// Purpose: Override activities
//
//-----------------------------------------------------------------------------
Activity CSDKHeadcrab::NPC_TranslateActivity( Activity eNewActivity )
{
if ( eNewActivity == ACT_MELEE_ATTACK1) {
// the regular headcrab actually does a range attack by jumping at you, so the mdl
// doesn't have a melee attack, so we fudge the attack activity
return ACT_RANGE_ATTACK1;
}
else
{
return eNewActivity;
}
}
//-----------------------------------------------------------------------------
// Purpose: Handle animation events
//
//-----------------------------------------------------------------------------
void CSDKHeadcrab::HandleAnimEvent( animevent_t *pEvent )
{
// Animation events are triggered by the mdl;
// we handle the attack related events to prevent errors about unhandled events
if ( pEvent->event == AE_HEADCRAB_JUMPATTACK )
{
DevMsg("JumpAttack!"); // no damage for now, have to look into melee damage some more
return;
}
if ( pEvent->event == AE_HEADCRAB_JUMP_TELEGRAPH )
{
return;
}
BaseClass::HandleAnimEvent( pEvent );
}
// Declare all your custom activities, tasks, schedules, and animation events here
AI_BEGIN_CUSTOM_NPC( sdk_headcrab, CSDKHeadcrab )
DECLARE_ANIMEVENT( AE_HEADCRAB_JUMPATTACK )
DECLARE_ANIMEVENT( AE_HEADCRAB_JUMP_TELEGRAPH )
AI_END_CUSTOM_NPC()
Вот qc фаил краба:
$cd "D:\games\soursemodels\PAPKA1"
$modelname "headcrabclassic.mdl"
$model "studio" "headcrab_reference.smd"
$lod 12
{
replacemodel "headcrab_reference" "lod1_headcrab_reference"
}
$lod 20
{
replacemodel "headcrab_reference" "lod2_headcrab_reference"
}
$lod 30
{
replacemodel "headcrab_reference" "lod3_headcrab_reference"
}
$shadowlod
{
replacemodel "headcrab_reference" "lod4_headcrab_reference"
}
$cdmaterials "models\headcrab_classic\"
$hboxset "default"
$hbox 0 "HeadcrabClassic.BodyControl" -3.500 -6.000 -7.170 13.500 4.000 7.170
$hbox 0 "HeadcrabClassic.ForeArmL_Bone" 0.000 -0.500 -1.000 8.000 1.500 1.000
$hbox 0 "HeadcrabClassic.UpperArmL_Bone" -0.500 -1.000 -1.000 8.500 1.000 1.000
$hbox 0 "HeadcrabClassic.UpperArmR_Bone" -0.500 -1.000 -1.000 8.500 1.000 1.000
$hbox 0 "HeadcrabClassic.ForeArmR_Bone" 0.000 -1.500 -1.000 8.000 0.500 1.000
$hbox 0 "HeadcrabClassic.CalfR_Bone" -0.250 -0.500 -1.000 4.250 1.500 1.000
$hbox 0 "HeadcrabClassic.CalfL_Bone" -0.250 -1.000 -1.000 4.250 1.000 1.000
// Model uses material "headcrabsheet.vmt"
$surfaceprop "alienflesh"
$eyeposition 0.000 0.000 16.000
$illumposition -0.590 -0.099 7.166
$sequence Idle01 "Idle01" loop ACT_IDLE 1 fps 30.00
$sequence Run1 "Run1" loop ACT_RUN 1 fps 30.00
$sequence jumpattack_broadcast "jumpattack_broadcast" ACT_RANGE_ATTACK1 1 fps 30.00 {
{ event AE_FAR_JUMP_TELEGRAPH 0 }
{ event AE_FAR_JUMPATTACK 5 }
}
$sequence ragdoll "ragdoll" ACT_DIERAGDOLL 1 fps 30.00
$collisionjoints "phymodel.smd" {
$mass 5.0
$inertia 5.00
$damping 0.01
$rotdamping 1.50
$rootbone "headcrabclassic.bodycontrol"
$jointconstrain "headcrabclassic.thighl_bone" x limit -37.00 12.00 0.20
$jointconstrain "headcrabclassic.thighl_bone" y limit -39.00 46.00 0.20
$jointconstrain "headcrabclassic.thighl_bone" z limit -44.00 46.00 0.20
$jointconstrain "headcrabclassic.thighr_bone" x limit -30.00 19.00 0.20
$jointconstrain "headcrabclassic.thighr_bone" y limit -39.00 47.00 0.20
$jointconstrain "headcrabclassic.thighr_bone" z limit -44.00 46.00 0.20
$jointconstrain "headcrabclassic.calfr_bone" x limit 0.00 0.00 0.00
$jointconstrain "headcrabclassic.calfr_bone" y limit 0.00 0.00 0.00
$jointconstrain "headcrabclassic.calfr_bone" z limit -77.00 57.00 0.20
$jointconstrain "headcrabclassic.upperarmr_bone" x limit -37.00 64.00 0.20
$jointconstrain "headcrabclassic.upperarmr_bone" y limit -53.00 23.00 0.20
$jointconstrain "headcrabclassic.upperarmr_bone" z limit -61.00 55.00 0.20
$jointconstrain "headcrabclassic.forearmr_bone" x limit 0.00 0.00 0.00
$jointconstrain "headcrabclassic.forearmr_bone" y limit 0.00 0.00 0.00
$jointconstrain "headcrabclassic.forearmr_bone" z limit -84.00 39.00 0.20
$jointconstrain "headcrabclassic.upperarml_bone" x limit -64.00 35.00 0.20
$jointconstrain "headcrabclassic.upperarml_bone" y limit -23.00 39.00 0.20
$jointconstrain "headcrabclassic.upperarml_bone" z limit -44.00 53.00 0.20
$jointconstrain "headcrabclassic.forearml_bone" x limit 0.00 0.00 0.00
$jointconstrain "headcrabclassic.forearml_bone" y limit 0.00 0.00 0.00
$jointconstrain "headcrabclassic.forearml_bone" z limit -70.00 48.00 0.20
$jointconstrain "headcrabclassic.calfl_bone" x limit 0.00 0.00 0.00
$jointconstrain "headcrabclassic.calfl_bone" y limit 0.00 0.00 0.00
$jointconstrain "headcrabclassic.calfl_bone" z limit -95.00 57.00 0.20
}
Все скомпилил, краба на карту поставил запустил карту вот что было написанно в консоле после того как я подошел и отошел от краба:
JumpAttack!JumpAttack!JumpAttack!JumpAttack!
npc_headcrab thinking for 44.55ms!!! (SCHED_CHASE_ENEMY); r43.81 (c0.15, pst0.00, ms43.65), p-r0.04, m0.65
npc_headcrab thinking for 25.44ms!!! (SCHED_CHASE_ENEMY_FAILED); r25.34 (c0.13, pst0.00, ms25.21), p-r0.04, m0.01
npc_headcrab moving with speed <= 0 (Run1)
npc_headcrab moving with speed <= 0 (Run1)
меня интересует вот эта строка: moving with speed <= 0 (Run1) где я должен указать скорость перидвижения?
Почему краб не двигается по миру?
И почему краб все время поворачивается ко мне боком когда замечает меня?