Hey coders!

I came across a nasty little issue and I thought maybe somebody has come
across this before.
I am trying to create a client side beam from the muzzle of the players view
model to where the bullet impacts, but I cannot get the attachment position
for the muzzle on the view model.

Here is the code I am using for getting the attachment:

    int    attachment = pEntity->LookupAttachment( "muzzle" );
    pEntity->GetAttachment( attachment, vecAttachment, angAttachment );

pEntity is the view model.
This is the same way I saw it done on the physcannons client side code.
The position it gets appears to be somewhere close to the origin of the map
but the coordinates are not exactly 0, 0, 0. One way to fix the position is
to give myself a weapon_physcannon and then when I switch back to my gun the
attachment position is where it should be, from the muzzle. I don't see
anything special in the weapon_physcannon's code so I am baffled.

Some things to note:
- This is a client side entity, client side code
- The attachment on the model looks fine in the model viewer

So any help would be wonderful, I am just digging away at the debugging
trying to find the issue but nothing sticks out, only the fact that having a
physcannon at the same time fixes the problem.

Here is the full code for the beam just in case:

void C_WeaponSonicRifle::CreateShotBeam(void)
{
    CBasePlayer *pOwner = ToBasePlayer( GetOwner() );

    if ( pOwner == NULL )
        return;

    BeamInfo_t beamInfo;
    C_BaseAnimating *pEntity = NULL;
    trace_t tr;

    Vector    vecAttachment, vecCrosshair, vecDir;
    QAngle    angAttachment;

    if ( IsCarriedByLocalPlayer() && !::input->CAM_IsThirdPerson() )
    {
        pEntity = pOwner->GetViewModel();
        vecDir = pOwner->GetAutoaimVector(AUTOAIM_5DEGREES);
    }
    else
    {
        pEntity = this;
        vecDir = pOwner->GetAutoaimVector(AUTOAIM_5DEGREES);
    }

    pEntity->PushAllowBoneAccess( true, true, "sonic rifle" );

    int    attachment = pEntity->LookupAttachment( "muzzle" );
    pEntity->GetAttachment( attachment, vecAttachment, angAttachment );

    pEntity->PopBoneAccess( "sonic rifle" );

    vecCrosshair = pOwner->Weapon_ShootPosition();
    UTIL_TraceLine(vecCrosshair, vecCrosshair + (vecDir * MAX_TRACE_LENGTH),
MASK_SONICBEAMS, pOwner, COLLISION_GROUP_NONE, &tr);

    beamInfo.m_pStartEnt = NULL;
    beamInfo.m_pEndEnt = NULL;

    //beamInfo.m_nType = TE_BEAMPOINTS;
    beamInfo.m_vecStart = tr.endpos;
    beamInfo.m_vecEnd = vecAttachment;

    beamInfo.m_nStartAttachment = NULL;
    beamInfo.m_nEndAttachment = NULL;

    beamInfo.m_pszModelName = "sprites/laserbeam.vmt";
    beamInfo.m_flHaloScale = 0.0f;
    beamInfo.m_flLife = 2.5f;

    beamInfo.m_flWidth = 3.0f;
    beamInfo.m_flEndWidth = 3.0f;

    beamInfo.m_flFadeLength = 0.0f;
    beamInfo.m_flAmplitude = 0;

    beamInfo.m_flBrightness = 255.0;

    beamInfo.m_flSpeed = 1.0f;
    beamInfo.m_nStartFrame = 0.0;
    beamInfo.m_flFrameRate = 30.0;

    beamInfo.m_flRed = 255;
    beamInfo.m_flGreen = 255;
    beamInfo.m_flBlue = 255;

    beamInfo.m_nSegments = 4;
    beamInfo.m_bRenderable = true;
    beamInfo.m_nFlags = (FBEAM_SHADEIN | FBEAM_SHADEOUT | FBEAM_FADEOUT);

    beams->CreateBeamPoints( beamInfo );
}

Thanks guys :)

-- 
~Ryan ( skidz )
_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives, please 
visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders

Reply via email to