Hitscan: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
TomEdwards (talk | contribs) (Category:Weapons programming, syntax highlight) |
||
Line 1: | Line 1: | ||
For a more technical article on this topic, see [[Using TraceLines|Using TraceLines]]. | For a more technical article on this topic, see [[Using TraceLines|Using TraceLines]]. | ||
Half-Life 2 has many hitscan weapons (weapons which don't actually fire bullets, but instead trace a line and spawn an explosion/damage at the end). Sometimes it is useful, however, to hitscan just to find where a line hits a wall/player/etc. So I took some code from <code>CBaseEntity::FireBullets()</code> to create <code>CBaseEntity::HitScan()</code>. I put the following code into <code>baseentity_shared.ccp</code>. | Half-Life 2 has many hitscan weapons (weapons which don't actually fire bullets, but instead trace a line and spawn an explosion/damage at the end). Sometimes it is useful, however, to hitscan just to find where a line hits a wall/player/etc. So I took some code from <code>CBaseEntity::FireBullets()</code> to create <code>CBaseEntity::HitScan()</code>. I put the following code into <code>baseentity_shared.ccp</code>. | ||
< | <source lang=cpp> | ||
Vector CBaseEntity::HitScan( const FireBulletsInfo_t &info, unsigned int mask ) | Vector CBaseEntity::HitScan( const FireBulletsInfo_t &info, unsigned int mask ) | ||
{ | { | ||
Line 14: | Line 12: | ||
return tr.endpos; | return tr.endpos; | ||
} | } | ||
</ | </source> | ||
and the definition into <code>BaseEntity.h</code>. | and the definition into <code>BaseEntity.h</code>. | ||
< | <source lang=cpp> | ||
virtual Vector HitScan( const FireBulletsInfo_t &info, unsigned int mask ); | virtual Vector HitScan( const FireBulletsInfo_t &info, unsigned int mask ); | ||
</ | </source> | ||
This function can easily be adapted to take line definitions in other formats. Simply have it generate the FireBulletsInfo_t structure given a start and end or start and direction. | This function can easily be adapted to take line definitions in other formats. Simply have it generate the FireBulletsInfo_t structure given a start and end or start and direction. | ||
[[Category:Weapons programming]] |
Revision as of 09:41, 15 August 2009
For a more technical article on this topic, see Using TraceLines.
Half-Life 2 has many hitscan weapons (weapons which don't actually fire bullets, but instead trace a line and spawn an explosion/damage at the end). Sometimes it is useful, however, to hitscan just to find where a line hits a wall/player/etc. So I took some code from CBaseEntity::FireBullets()
to create CBaseEntity::HitScan()
. I put the following code into baseentity_shared.ccp
.
Vector CBaseEntity::HitScan( const FireBulletsInfo_t &info, unsigned int mask )
{
trace_t tr;
CTraceFilterSkipTwoEntities traceFilter( this, info.m_pAdditionalIgnoreEnt, COLLISION_GROUP_NONE );
Vector vecEnd = info.m_vecSrc + info.m_vecDirShooting * info.m_flDistance;
AI_TraceLine(info.m_vecSrc, vecEnd, mask, &traceFilter, &tr);
return tr.endpos;
}
and the definition into BaseEntity.h
.
virtual Vector HitScan( const FireBulletsInfo_t &info, unsigned int mask );
This function can easily be adapted to take line definitions in other formats. Simply have it generate the FireBulletsInfo_t structure given a start and end or start and direction.