Bullet Problem

Blitz3D Forums/Blitz3D Beginners Area/Bullet Problem

Greetings. I am pretty new to Blitz3D and this is my first post on this site.
I am currently having a problem with a first person shooter that I am attemping to make.
The problem is that when ever I shoot my bullet, it appears to rotate where my gun is so that when I turn 180% around the bullets fire from a different position than where I intended (the barrel of the gun).
I've tried to solve this on my own and haven't figured it out.
As I've observed on this website, it appears to help to give an example of code, so here it is:

;FPS

Graphics3D 1024,764
SetBuffer BackBuffer()
light=CreateLight()

;Creating the camera and pivot
piv=CreatePivot(cam)
cam=CreateCamera()
TranslateEntity piv,EntityX(cam),EntityY(cam),EntityZ(cam)
ScaleEntity cam,1,1,1

;Creating a plane
plane=CreatePlane()
PositionEntity plane,0,-2,0
EntityColor plane,0,255,0

;Creating the gun
gun=LoadMesh("C:\Program Files\AutoDesk\3DsMax8\meshes\Gun.3ds")
PositionEntity gun,.2,-.25,.5
ScaleEntity gun,.005,.005,.005
RotateEntity gun,0,90,-90
EntityParent gun,cam

;How far the camera can see
cam_range=10000
;How near the camera can see
CameraRange cam,.1,cam_range

;Creating the bullets
fullmag=100
Dim bullet(fullmag)
For i=0 To fullmag
bullet(i)=CreateSphere()
ScaleEntity bullet(i),.2,.2,.4
HideEntity bullet(i)
Next

;Function CurveValue
Function CurveValue#(current#,destination#,curve)
current#=current#+((destination#-current#)/curve)
Return current#
End Function

;Running the program
While Not KeyDown(1)

;Mouse controls
mxs=MouseXSpeed()*.25
mys=MouseYSpeed()*.25

dest_xangle#=dest_xangle#+mys
dest_yangle#=dest_yangle#-mys

xangle#=CurveValue#(xangle#,dest_xangle#,3)
yangle#=CurveValue#(yangle#,dest_yangle#,3)

RotateEntity cam,xangle#,yangle#,0

MoveMouse GraphicsWidth()/2,GraphicsHeight()/2

;Firing bullets
If MouseHit(1) Then
ShowEntity bullet(t)
PositionEntity bullet(t),EntityX(gun,1)+.5,EntityY(gun,1)-1.5,EntityZ(gun,1)
RotateEntity piv,EntityPitch#(cam,1),EntityYaw#(cam,1),EntityRoll#(cam,1)
RotateEntity bullet(t),EntityPitch#(piv,1),EntityYaw#(piv,1),EntityRoll#(cam,1)
t=t+1
EndIf

For q=0 To fullmag
MoveEntity bullet(q),0,1,3
Next

RenderWorld
Flip

Wend

End


If I typed any commands wrong, it's becaus I had to retype all that code.
The computer with Blitz3D doesn't have internet access.
I tried to include everything that I assumed you needed but if I missed anything important then just let me know.
Thanks in advance!

There are various methods but if you change this part ...

If MouseHit(1) Then
ShowEntity bullet(t)
PositionEntity bullet(t),EntityX(gun,1)+.5,EntityY(gun,1)-1.5,EntityZ(gun,1)
RotateEntity piv,EntityPitch#(cam,1),EntityYaw#(cam,1),EntityRoll#(cam,1)
RotateEntity bullet(t),EntityPitch#(piv,1),EntityYaw#(piv,1),EntityRoll#(cam,1)
t=t+1
EndIf


To ...

If MouseHit(1) Then
ShowEntity bullet(t)
entityparent bullet(t), gun
positionentity bullet(t), .5,-1.5,0   ;??
rotateentity bullet(t),0,0,0
entityparent bullet(t), 0
t=t+1
EndIf


It should work for you. Not sure about the .5, -1.5 offsets - note that these will be the local coords relative to the gun so you may want to play with them.

Stevie

Excellent!
Thank you very much.
I did have to tweak the numbers a bit but it will work.
I find it strange that sometimes the 0,0,0 dosn't always mean x,y,z.
That I don't understand but I'm sure I'll get used to it.