A lot of people use a limb that is attached to the player object so that you get the same effect as AndrewT mentioned, without worrying about moving the object every cycle.
Here is some code that does this:
` Setup code
sync on : sync rate 60
set display mode 1024, 786, 32
` Objects
#constant OBJ_PLAYER 1
#constant OBJ_WEAPON 2
` Meshes
#constant MESH_WEAPON 1
` Limbs
#constant LIMB_WEAPON 1
` Make Player object
make object box OBJ_PLAYER, 10, 25, 5
ghost object on OBJ_PLAYER
` Make Weapon object
make object cylinder OBJ_WEAPON, 10
` Just to make it look like a weapon, gun...
scale object OBJ_WEAPON, 50.0, 150.0, 50.0
xrotate object OBJ_WEAPON, 90
fix object pivot OBJ_WEAPON
` Need to make the Player a mesh so we can add the limb
make mesh from object MESH_WEAPON, OBJ_WEAPON
` Technically you dont need the weapon object anymore, so we can clear it from memory
delete object OBJ_WEAPON
` Here we add the limb
add limb OBJ_PLAYER, LIMB_WEAPON, MESH_WEAPON
` Here we offset the limb to where we want it.
offset limb OBJ_PLAYER, LIMB_WEAPON, 10, 10, 10
` Variables
MoveSpeed# = 0.05
` Begin our loop.
do
` User Input
move object OBJ_PLAYER, ( upkey()-downkey() + keystate(17)-keystate(31) ) * MoveSpeed#
yrotate object OBJ_PLAYER, wrapvalue( object angle y(OBJ_PLAYER) + mousemovex() )
rotate limb OBJ_PLAYER, LIMB_WEAPON, camera angle x(), 0.0, 0.0
` Make the camera follow the player.
CameraFollowObject( OBJ_PLAYER )
sync
loop
` Just a function to make the camera do a 3rd person follow
function CameraFollowObject( Object as integer )
ox# = object position x( OBJ_PLAYER )
oy# = object position y( OBJ_PLAYER )
oz# = object position z( OBJ_PLAYER )
angy# = object angle y(OBJ_PLAYER)
angx# = camera angle x( ) + mousemovey()/2.0
nx# = ox# + 10.0 * sin( angy# + 180.0)
ny# = oy# + 10.0 + 5.0 * cos( angx# )
nz# = oz# + 10.0 * cos( angy# + 180.0 )
s# = .002
position camera nx#, ny#, nz#
yrotate camera angy#
xrotate camera angx#
endfunction
EDIT: changed keystates to 17 and 31