Hitscan: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (Bad form to talk about yourself in a wiki article. Even worse not to state who you are.)
mNo edit summary
Line 1: Line 1:
{{otherlang2
|de=Hitscan:de
|es=Hitscan:es
|fr=Hitscan:fr
|ka=Hitscan:ka
|nl=Hitscan:nl
|pl=Hitscan:pl
|ru=Hitscan:ru
|zh-cn=Hitscan:zh-cn
|zh-tw=Hitscan:zh-tw
}}
<small>''For a more technical article on this topic, see [[UTIL_TraceLine|TraceLines]].''</small>
<small>''For a more technical article on this topic, see [[UTIL_TraceLine|TraceLines]].''</small>



Revision as of 06:27, 9 November 2021

Template:Otherlang2 For a more technical article on this topic, see 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.