Congrats on the rite of passage, hopefully it didn't involve running on the backs of cattle* or anything too painful to mention.
The code changes for a relative placement of the gun are attached. Works like a charm for me. I replaced your gun with one of my own so you will need to uncomment your code there. I didn't use roll object or move right since I don't know what DBC supports.
Rem Setup sync
Sync On
Sync Rate 30
autocam off
hide mouse
Rem make matrix
Make matrix 1,10000,10000,20,20
position matrix 1,-500,-200,-500
Rem texture matrix
Load image "sand.bmp",1
Prepare matrix texture 1,1,2,2
Rem Randomize the matrix
randomize matrix 1,250
Rem Place random texture on each matrix tile
For x = 0 to 19
For z = 0 to 19
t = rnd(3)+1
Set Matrix Tile 1,x,z,t
Next z
Next x
Rem Update the changes to the matrix
update matrix 1
Rem Make Cubes for reference
For x = 1 to 5
Make object cube x,100
Position object x,Rnd(2000),0,Rnd(2000)
Set object collision to boxes x
Next x
Rem make the m4a1 machine gun
`load object "m4a1.3ds",10
`scale object 10,2,2,2
load object "rifle_1.x",10
scale object 10,40,40,40
yrotate object 10, 180
fix object pivot 10
position object 10,0,0,0
set object collision to boxes 10
make object plain 6, 1,1
color object 6, rgb(255,0,0)
angle_up# = 0
angle_side# = 0
Rem Main loop
Do
set cursor 0,0
ay# = object angle y(10)
print ay#
rem store the gun's position
gX# = object position x(10)
gY# = object position y(10)
gZ# = object position z(10)
rem the technique that I'm going to use is that the camera is the player's head
rem and all movement and positions are based on that.
rem get the current position. We'll assume that world coordinates are in meters
rem so the camera is 175cm above the matrix
X# = camera position x()
Z# = camera position z()
Y# = Get Ground Height(1,X#,Z#)
rem this is basically 'mouse sensitivity'
angle_up#=wrapvalue(angle_up#+mousemovey()/10)
angle_side#=wrapvalue(angle_side#+mousemovex()/10)
rem rotate the camera
rotate camera angle_up#, angle_side#, 0
Rem Control input for movement
If Upkey()=1
move camera 20
Endif
If downkey()=1
move camera -20
Endif
rem strafing
If leftkey()=1
position camera x#-20,y#,z#
Endif
If rightkey()=1
position camera x#+20,y#,z#
Endif
rem get new ground height
X# = camera position x()
Z# = camera position z()
Y# = Get Ground Height(1,X#,Z#)
rem reposition the camera
position camera X#,Y#,Z#
rem align and position gun
rotate object 10, camera angle x(),camera angle y(),camera angle z()
position object 10, X#,Y#,Z#
rem offset gun to the right
turn object right 10,90.0
move object 10, .50
turn object left 10, 90.0
rem move gun down a bit
pitch object down 10, 90.0
move object 10,1.1
pitch object up 10,90.0
rem move it forward to show off the gun a bit more
move object 10, .04
rem align, position, and project cursor
rotate object 6, camera angle x(),camera angle y(),camera angle z()
position object 6, X#,Y#,Z#
move object 6, 30.0
Rem Refresh Screen
Sync
Loop
If you want me to send my rifle model over for testing, just drop me a line via e-mail. If you think about the offsets, the trigger (the 0,0,0 origin point of my model) is around the hip level and a bit forward. While it may not be the best firing position, it prevents that cut-away model effect.
Quote: "Speaking of problems, you are using a model I don't have (the M4.) It is entirely possible that it has some whacked origin offset that is skewing the whole thing. Can you tell where the pivot point of the model is?
"
This is still an important question you need to answer. If the origin point of the M4 model is not near the gun, you are going to have serious problems rotating it.
--
TAZ
* Yes, there is a tribe in Africa where that is part of the ritual.