VERC: View Turrets through Barrel Last edited 2 years ago2022-09-29 07:55:51 UTC

One of the most difficult things in Half-Life is trying to control the turrets. You never seem to have a good angle and it can take ages to get the hang of controlling them. This article describes how you can put the 'camera' so that it is looking straight out the barrel.

This is a very effective little trick, which requires barely two lines of code and the removal of a couple of lines. It works on virtually all the turrets in Half-Life.

First open up func_tank.cpp and scroll down to StartControl( ) and add the following to the sub
SET_VIEW( m_pController->edict(), ENT(pev));
This will set the view of the player ( m_pController ) to the view of me. Then go down to StopControl( ) and add the following
SET_VIEW( m_pController->edict(), m_pController->edict());
This should work a treat, then you have a small cosmetic issue. The flash of the gun barrel gets in the way, so go to Fire ( ) and remove or comment out..
if ( m_iszSpriteSmoke )
{
     CSprite *pSprite = CSprite::SpriteCreate( STRING(m_iszSpriteSmoke),
          barrelEnd, TRUE );
     pSprite->AnimateAndDie( RANDOM_FLOAT( 15.0, 20.0 ) );
     pSprite->SetTransparency( kRenderTransAlpha, pev->rendercolor.x,
          pev->rendercolor.y, pev->rendercolor.z, 255, kRenderFxNone );
     pSprite->pev->velocity.z = RANDOM_FLOAT(40, 80);
     pSprite->SetScale( m_spriteScale );
}
if ( m_iszSpriteFlash )
{
     CSprite *pSprite = CSprite::SpriteCreate( STRING(m_iszSpriteFlash),
          barrelEnd, TRUE );
     pSprite->AnimateAndDie( 60 );
     pSprite->SetTransparency( kRenderTransAdd, 255, 255, 255, 255,
          kRenderFxNoDissipation );
     pSprite->SetScale( m_spriteScale );

     // Hack Hack, make it stick around for at least 100 ms.
     pSprite->pev->nextthink += 0.1;
}
Thats it, now compile the dll and admire all your hard work.
This article was originally published on Valve Editing Resource Collective (VERC).
The archived page is available here.
TWHL only publishes archived articles from defunct websites, or with permission. For more information on TWHL's archiving efforts, please visit the TWHL Archiving Project page.

Comments

You must log in to post a comment. You can login or register a new account.