Named Game of the Year by over 50 publications, Valve's d├ębut title blends action and adventure with award-winning technology to create a frighteningly realistic world where players must think to survive. Also includes an exciting multiplayer mode that allows you to play against friends and enemies around the world.

Post tutorial RSS Fixing turning rate of monsters at high fps

We all know when you set high fps in Half-Life (like above 150 or so) the monsters begin to turn veeeery slowly and only after that doing their functions like running or shooting. This was fixed in 2019 in Steam version of Half-Life. This tutorial will help you to implement the same in your own mod, especially if you are working on Xash engine.

Posted by on - Basic Server Side Coding

Attention! This code is not written by me. The author of the code is Solokiller. The code is availaible in public on github but it was written without showing how to implement it. So I'm just redestributing his code in a way of complete function and easy-to-follow tutorial.

Let's begin! We are going to the server side of the game (server.dll).

Open the file monsters.cpp. Find the function:

float CBaseMonster::ChangeYaw ( int yawSpeed )

Delete this function or (better) comment it or cut from here and paste in some notepad just in case.
Replace it with this function:

float CBaseMonster::ChangeYaw ( int yawSpeed )
    float    ideal, current, move, speed;
    Vector    angles = GetAbsAngles();

    current = UTIL_AngleMod( angles.y );
    ideal = pev->ideal_yaw;
    if (current != ideal)
        float delta = gpGlobals->time - m_flLastYawTime;
        move = ideal - current;
        if( delta > 0.25 )
            delta = 0.25;
        speed = yawSpeed * delta * 2;

        const float originalSpeed = ( float ) yawSpeed * gpGlobals->frametime * 10;

        const float multiplier = originalSpeed / ( yawSpeed * delta );
        if (ideal > current)
            if (move >= 180)
                move = move - 360;
            if (move <= -180)
                move = move + 360;

        if (move > 0)
        {// turning to the monster's left
            if (move > speed)
                move = speed;
        {// turning to the monster's right
            if (move < -speed)
                move = -speed;
        angles.y = UTIL_AngleMod (current + move);

        // turn head in desired direction only if they have a turnable head
        if (m_afCapability & bits_CAP_TURN_HEAD)
            float yaw = pev->ideal_yaw - angles.y;
            if (yaw > 180) yaw -= 360;
            if (yaw < -180) yaw += 360;
            // yaw *= 0.8;
            SetBoneController( 0, yaw );

        SetAbsAngles( angles );
        move = 0;
        m_flLastYawTime = gpGlobals->time;
    return move;

As you may noticed, we have new parameter here m_flLastYawTime which must be registered in order for monsters.cpp to compile.
To do so, go to the top of monsters.cpp and find the string:


Right after it, you will see many strings that look like DEFINE_FIELD. At the end of this section, before the line END_DATADESC() we are going to add our new line:


Now we are finished with monsters.cpp file, but it's not going to compile just yet.

Let's find the file basemonster.h and open it. Find this code there:

class CBaseMonster : public CBaseToggle
        DECLARE_CLASS( CBaseMonster, CBaseToggle );

        int    m_afConditions;


In the public section you will see many "int"s and "float"s being registered. We need to do the same. Add our new line there:

float                m_flLastYawTime;  // FPS fix

And we are done! Close the file, then go back to monsters.cpp and compile it. There shouldn't be any errors. Now you can compile your server.dll and enjoy.

Set fps_max to 1000 or so in the game and see that monster turning is now working well regardless of the fps set. :)

Post a comment
Sign in or join with:

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.

Follow Profile
Windows, Mac, Linux, PS2
Send Message
Release date
Game watch
Related Games
Half-Life First Person Shooter
Related Engines
GoldSrc Commercial
Related Groups
Sierra Entertainment
Sierra Entertainment Developer & Publisher
Valve Developer & Publisher