Instead of the user's origin, I would suggest using the origin from his eyes:
PHP Code:
#include <amxmodx>
#include <fakemeta_util>
#define VERSION "1.0"
#define HEAD_POSITION 8
#define DESIRED_DISTANCE 100 // Change this to whatever.
new g_entid;
public plugin_init()
{
register_plugin( "Moving an entity by the aim", VERSION, "Dores" );
register_forward( FM_PlayerPreThink, "Forward_PreThink" );
register_clcmd( "say /ent", "Cmd_Create" );
}
public Cmd_Create( id )
{
new Float:aimorigin[ 3 ];
fm_get_aim_origin( id, aimorigin );
g_entid = fm_create_entity( "info_target" );
set_pev( g_entid, pev_classname, "BlaBla" );
set_pev( g_entid, pev_movetype, MOVETYPE_FOLLOW );
set_pev( g_entid, pev_owner, id );
// ETC. - Create entity with your likings.
return PLUGIN_HANDLED;
}
public Forward_PreThink( id )
{
if( !is_user_alive( id ) )
return FMRES_IGNORED;
static Float:start[ 3 ], Float:Forward[ 3 ], Float:end[ 3 ];
engfunc( EngFunc_GetBonePosition, id, HEAD_POSITION, start );
pev( id, pev_v_angle, Forward );
engfunc( EngFunc_MakeVectors, Forward );
global_get( glb_v_forward, Forward );
end[ 0 ] = start[ 0 ] + Forward[ 0 ] * DESIRED_DISTANCE;
end[ 1 ] = start[ 1 ] + Forward[ 1 ] * DESIRED_DISTANCE;
end[ 2 ] = start[ 2 ]; // Height of the eyes.
engfunc( EngFunc_SetOrigin, g_entid, end ); // Update the ent's origin.
return FMRES_IGNORED;
}
__________________