changing NPC walking speed Created 6 years ago2018-09-12 12:21:04 UTC by hfc hfc

Created 6 years ago2018-09-12 12:21:04 UTC by hfc hfc

Posted 6 years ago2018-09-12 12:21:04 UTC Post #340855
i couldn't find in the sdk
Posted 6 years ago2018-09-12 13:40:55 UTC Post #340856
The code doesn't handle that, the sequence/animation in the model's QC does.
Posted 6 years ago2018-09-12 13:47:50 UTC Post #340857
ok thanks :)
Posted 6 years ago2018-09-12 13:57:42 UTC Post #340858
but how game knows which animation sequence belongs to movement?
Posted 6 years ago2018-09-12 16:04:29 UTC Post #340859
The game looks up animations based on which activity is associated with the animation.
Posted 6 years ago2018-09-12 16:18:17 UTC Post #340860
are there any associations on codes? i dont see walk animations' names defined in sdk.
Posted 6 years ago2018-09-12 16:51:09 UTC Post #340861
This is the list of activities: https://github.com/ValveSoftware/halflife/blob/master/dlls/activity.h

The game looks up which animation has the activity set for it. Check the QC file for which animations have which activities.

As far as movement goes, each animation defines how far it moves. The root bone is used to determine where the animation starts and ends, end - start (position in last frame - position in first frame) determines how far movement goes, the rotation defined for the animation affects which direction movement will go in.

Movement speed is determined by movement distance * (framerate / number of frames - 1). The fewer frames and the higher the framerate, the faster movement will be.
If there are no frames then movement speed is always 0.

None of the models in the SDK specify rotation, so don't be surprised if it doesn't work properly.

The function used to extract movement speed can be found here: https://github.com/ValveSoftware/halflife/blob/5d761709a31ce1e71488f2668321de05f791b405/dlls/animation.cpp#L226

pflGroundSpeed is movement speed, pflFrameRate is the framerate for the animation, which is independent of the entity framerate. The final framerate is pflFrameRate * entity framerate, so movement speed will be affected by that as well.

The actual movement is performed here: https://github.com/ValveSoftware/halflife/blob/5d761709a31ce1e71488f2668321de05f791b405/dlls/monsters.cpp#L1980

Some entities may override this so check their MoveExecute method. If you wanted to, you could add a keyvalue that overrides the animation movement speed, or that multiplies it to speed up/slow down the entity.
Posted 6 years ago2018-09-13 06:36:07 UTC Post #340862
I have to ask more sorry but im not a professional coder. :)

void CXenTree :: Attack( void )
{
if ( GetActivity() == ACT_IDLE )
{
SetActivity( ACT_MELEE_ATTACK1 );
pev->framerate = RANDOM_FLOAT( 1.0, 1.4 );
EMIT_SOUND_ARRAY_DYN( CHAN_WEAPON, pAttackMissSounds );
}
}

When i check tree.mdl there is 2 animations. idle1 and attack
Second animation is attack and indexed 1 (the other one is indexed 0)
But how game knows attack in model file is actually ACT_MELEE_ATTACK1 from activity.h

Is there a list says;
ACT_MELEE_ATTACK1 = attack
ACT_IDLE = idle1
Posted 6 years ago2018-09-13 07:16:49 UTC Post #340863
QC file
Posted 6 years ago2018-09-13 08:30:07 UTC Post #340864
thank you both of you :) problem solved. But unfortunatery it seems i have to study way more for modding.
Posted 6 years ago2018-09-14 01:31:28 UTC Post #340872
Yes, it will have to be done via animation creation. A quick breakdown:

Here is an imported scientist model walk and what it looks like in blender:
User posted image
Im using an example from the gordon scientist model in bshift who's walking sequence moves Bip01 forward about 48 units (-48Y as it says in the blender inspector) which means he will move 48 hammer units per animation cycle (how ever many frames at how ever fps, this gif does not represent final fps).

Now basically in order to make an NPC "move" you make a walking animation and have the root bone (Often called "Bip01" as per standard HL skeletons) keyframed to move forward a set distance (depending how fast your custom NPC is moving) and with linear keyframes for just that root bone. See my above example of that scientist walk

The way I test to see if extraction is working is open the compiled model in HLMV and go to the "walk" animation. If it is walking in place then the extraction worked.

A while back I made 2 methods of "fixing" walk animations that drag but this exact method can be used to change existing NPC movement speeds, so use a higher number for more distance per loop cycle and a lower number for slower distance per loop cycle
Blender method
3dsmax method
Posted 6 years ago2018-09-14 15:40:05 UTC Post #340877
gonna read all of your tuts thanks.
You must be logged in to post a response.