CS 1.6 Custom 3rd Person View

For scripting examples for learning how to use AMXX.
User avatar
Archive-Poster
Posts: 1229
Gender:
United States of America

CS 1.6 Custom 3rd Person View

Post by Archive-Poster »

Hey guys, I was messing around and made my own 3rd person camera. This camera has several different things compared with using set_view from engine module.

Differences:
- Precision where your aiming is better.
- Your model isn't alpha'd.
- Your model stutters a bit with this method.
- Doesn't require rocket.mdl (uses a weapon file from mod thats already precached)

Heres the code using ENGINE module. It can be converted to FAKEMETA tho.

Code: Select all

//Call this wherever you want.
Create_PlayerCamera( id )
{
    new entid;
    while( (entid = find_ent_by_class(entid, "PlayerCamera")) != 0)
        if( entity_get_edict( entid, EV_ENT_owner ) == id )
        {
            attach_view( id, entid );
            return;
        }
        
    entid = create_entity("info_target");
        
    if(entid)
    {
        entity_set_string(entid,EV_SZ_classname,"PlayerCamera");
        entity_set_model(entid,"models/w_usp.mdl");
        entity_set_int( entid, EV_INT_solid, SOLID_TRIGGER);
        entity_set_int( entid, EV_INT_movetype, MOVETYPE_FLY );
        
         //Set owner
        entity_set_edict( entid, EV_ENT_owner, id );
        //Don't draw
        entity_set_int( entid, EV_INT_rendermode, kRenderTransTexture);
        entity_set_float( entid, EV_FL_renderamt, 0.0);
        //Attach our view to this entity.
        attach_view( id, entid ); 
        //Think!
        entity_set_float( entid, EV_FL_nextthink, get_gametime() );
    }   
}


//Requires registering a Think method for "PlayerCamera" entity. 
// OR you could save the camera's entity ID in the function above
// and call this in client_PostThink or wherever that gets called alot.
public Think_PlayerCamera( entid )
{
    new id = entity_get_edict( entid, EV_ENT_owner );
    
    //Kill our entity if we hit USE key
    new buttons = entity_get_int( id, EV_INT_button );
    if(buttons & IN_USE)
    {
        attach_view( id, id );
        remove_entity(entid);
        return;
    }

    new Float:origin[3], Float:angle[3], Float:vBack[3];
    entity_get_vector( id, EV_VEC_origin, origin );
    entity_get_vector( id, EV_VEC_v_angle, angle );

    angle_vector( angle, ANGLEVECTOR_FORWARD, vBack );

    origin[2] += 20.0; //So we're closer to the eyes.
    
    //Move back to see ourself (150 units)
    origin[0] += (-vBack[0] * 150.0);
    origin[1] += (-vBack[1] * 150.0);
    origin[2] += (-vBack[2] * 150.0);

    entity_set_origin( entid, origin );
    entity_set_vector( entid, EV_VEC_angles, angle );   
    
    //For thinking only
    entity_set_float( entid, EV_FL_nextthink, get_gametime() );
}
That's it. You can change how the player can turn this off if you don't want to use my USE key method, just copy attach_view( id, id ); and remove_entity(entid); where you want to do it.
Attachments
thirdperson.jpg
thirdperson.jpg (40.41 KiB) Viewed 20 times

Who is online

Users browsing this forum: No registered users and 0 guests