PDA

View Full Version : Is this code snippet right?


Arkanj3l
05-22-2007, 03:42 PM
//Code based off http://developer.valvesoftware.com/wiki/Using_TraceLines and http://developer.valvesoftware.com/wiki/Making_a_concussion_grenade

CBasePlayer *pPlayer = UTIL_GetLocalPlayer();

// set up the vectors and traceline
trace_t tr;
Vector vecStart, vecStop, vecDir;

// get the angles
AngleVectors( pPlayer->EyeAngles( ), &vecDir );

// get the vectors
vecStart = pPlayer->EyePosition();
vecStop = vecStart + vecDir * MAX_TRACE_LENGTH;

// do the traceline
UTIL_TraceLine( vecStart, vecStop, MASK_ALL, pPlayer, COLLISION_GROUP_NONE, &tr );

// check to see if we hit something
if ( tr.m_pEnt )
{
{
CBaseEntity *list[1024];
int count = UTIL_EntitiesInSphere(list,1024,GetAbsOrigin()+Vec tor(0,10,0),128,MASK_ALL);
for ( int i = 0; i < count; i++ )
{
if (list[i]->IsNPC())
{
//I do...something here... :S
}
}
}

}


I just KNOW something is wrong here.

lodle
05-22-2007, 04:23 PM
Why are you tracing to an ent then doing another sphere trace?

Ging
05-22-2007, 04:45 PM
Indeed - the sphere trace is an odd choice at that point, and you've got one too many sets of brackets round it too.

What are you actually trying to do?

Arkanj3l
05-22-2007, 09:50 PM
Get a flashlight to damage things.

Basically, it checks to see if the flashlight hits something. Since the flashlight is circular, it also has to check what is around the area.

Now that I think about it, one would probably set up a cone or something. I'm not sure how you would do that, though. It should be possible, I guess, because of weapon fire scattering...

lodle
05-22-2007, 09:55 PM
first of all you dont need the line trace then or change the check function so its checks if it hit something at all (if (tr.fraction != 1) {} ).

I think there is a cone type trace. Cant check as im not at home atm but i will later.

Arkanj3l
05-22-2007, 11:20 PM
Much obliged.

Ging
05-23-2007, 04:05 AM
There's no direct cone trace, but you can check if an entity is inside your view cone with CBaseCombatCharacter::FInViewCone, it should be fairly easy to modify that to account for the flashlights cone (just change the field of view it does the dot product check against).

So you'd want to perform a sphere trace from the players location, then iterate each valid entity in your list and check against that function (it just returns a bool) as to whether or not the entity needs to be damaged.