bullet prolem(change direction of bullet with gun)

Blitz3D Forums/Blitz3D Beginners Area/bullet prolem(change direction of bullet with gun)

hi,
I'm having a problem with my bullets, When I turn my gun, the bullets don't follow...How do I make it follow?
Also! I did search the forums for the anwser, but I don't think I found it...

here is the code...

Graphics3D 640,480
SetBuffer BackBuffer()

type_camera=1
type_entity=2


Function pause()
Text 100,150, "Game Paused - press any key (except P or start) to continue"

WaitKey()
WaitJoy()
End Function 



light=CreateLight()


camera=CreateCamera()
PositionEntity camera,1,1,0
CameraClsColor camera,92,236,222
EntityType camera, type_camera 
CameraRange camera,.001,1000



camera2=CreateCamera()
PositionEntity camera2,0,1,-5
CameraClsColor camera2,92,236,222
CameraRange camera2,.001,1000
EntityType camera2,type_camera





CameraViewport camera,0,0,GraphicsWidth()/2,GraphicsHeight()
CameraViewport camera2,GraphicsWidth()/2,0, GraphicsWidth()/2,GraphicsHeight()

camsphere=CreateSphere()
EntityType camsphere,type_camera
camsphere2=CreateSphere()

plane=CreatePlane()
EntityType plane, type_entity 


Ptex=LoadTexture("grass.jpg")
EntityTexture plane,ptex


mesh=LoadMesh("building1.b3d")
PositionEntity mesh,0,.35, 10
ScaleEntity mesh,.05,.05,.05
EntityType mesh, type_entity
;EntityRadius mesh,-1

gun=LoadMesh("guns\\w_fiveseven.3ds")
PositionEntity gun,1.1,.8,.3
ScaleEntity gun,.05,.05,.05
RotateEntity gun,90,-75,0
EntityParent gun,camera

fullcart=100
Dim bullet(fullcart)
For i=0 To fullcart
bullet(i)=CreateSphere()
EntityColor bullet(i),100,100,100
ScaleEntity bullet(i),0.2,0.4,0.2
HideEntity bullet(i)
Next











Collisions type_camera,type_entity,2,2

While Not KeyDown(1)






If KeyDown(208) Then MoveEntity camera2,0,0,-.15
If KeyDown(200) Then MoveEntity camera2,0,0,.15
If KeyDown(203) Then MoveEntity camera2,-.15,0,0
If KeyDown(205) Then MoveEntity camera2,.15,0,0
If KeyDown(30)  Then TurnEntity camera2,0,2,0,1
If KeyDown(32)  Then TurnEntity camera2,0,-2,0,1
If KeyDown(31) Then TurnEntity camera2,2,0,0
If KeyDown(17) Then TurnEntity camera2,-2,0,0







If JoyXDir() = -1 MoveEntity camera,-.15,0,0
If JoyXDir() = 1 MoveEntity camera,.15,0,0
If JoyYDir() = -1 MoveEntity camera,0,0,.15
If JoyYDir() = 1 MoveEntity camera,0,0,-.15

;If JoyXDir() = -1 TurnEntity camera,0,1,0
;If JoyXDir() = 1 TurnEntity camera,0,-1,0
;If JoyYDir() = -1 TurnEntity camera,-1,0,0
;If JoyYDir() = 1 TurnEntity camera,1,0,0

;If JoyDown(1) MoveEntity camera,-.1,0,0
;If JoyDown(3) MoveEntity camera,.1,0,0
;If JoyDown(4) MoveEntity camera,0,0,.1
;If JoyDown(2) MoveEntity camera,0,0,-.1

If JoyDown(1) TurnEntity camera,0,2,0,1
If JoyDown(3) TurnEntity camera,0,-2,0,1
If JoyDown(4) TurnEntity camera,-2,0,0
If JoyDown(2) TurnEntity camera,2,0,0
;If EntityY(camera) > 1.5 TranslateEntity camera,0,-1,0



If JoyHit(6) Then 
ShowEntity bullet(t)
PositionEntity bullet(t),EntityX(gun,1),EntityY(gun,1),EntityZ(gun,1)
EntityColor bullet(t),Rand(0,255),Rand(0,255),Rand(0,255)
t=t+1
End If 



For q=0 To fullcart
MoveEntity bullet(q),.3,.5,3
Next










PositionEntity camsphere,EntityX(camera),EntityY(camera),EntityZ(camera)
;MoveEntity camsphere,0,0,0

PositionEntity camsphere2,EntityX(camera2),EntityY(camera2),EntityZ(camera2)

;PositionEntity gun,EntityX(camera),EntityY(camera),EntityZ(camera)
;MoveEntity gun,0,1,10




If EntityY(camera)<2.0 Then PositionEntity camera,EntityX(camera),2.0,EntityZ(camera) 
If EntityY(camera2)<2.0 Then PositionEntity camera2,EntityX(camera2),2.0,EntityZ(camera2) 

TranslateEntity camera,0,-.15,0
TranslateEntity camera2,0,-.15,0

RenderWorld
UpdateWorld 

Text 0,0,EntityX(camera,True)
 Text 0,15,EntityY(camera,True)
 Text 0,30,EntityZ(camera,True) 

Text 600,0,EntityX(camera2,True)
 Text 600,15,EntityY(camera2,True)
 Text 600,30,EntityZ(camera2,True) 





If KeyDown(25) Then pause 
If JoyDown(10) Then pause
Flip


Wend

End


any help would be appreciated! thanks!

I may be able to help on this.
Try parenting the bullet to the camera (or gun) and when the bullet fires make the parent of the bullet '0' by typing "ParentEntity bullet(t),0".

Also, try putting this code under "PositionEntity bullet(t),EntityX(gun,1),EntityY(gun,1),EntityZ(gun,1)":
RotateEntity bullet(t),EntityPitch#(cam,1),EntityYaw#(cam,1),EntityRoll#(cam,1)


I believe I know where you got this code from.
I'll try looking at my own code and see if I can find anything.

Just turn the bullets to the pitch, yaw, and roll of the gun. Otherwise, they will always go in the same direction (you could also change "MoveEntity bullet(q),.3,.5,3" to "MoveEntity bullet(q),0,0,3").

Edit: By the way, I personally don't use parents, I've always had collision problems with them (I use a few entity position and rotation commands instead). Besides, they're too unpredictable :^)

HAH! thanks, I added the "entityparent bullet(t),0" and the

RotateEntity bullet(t),EntityPitch#(cam,1),EntityYaw#(cam,1),EntityRoll#(cam,1)

and it worked really well! thanks!

Well, glad to hear that you figured it out.
I found something different in my code but it probably doesn't matter.

You should check out WolRon's FPS example here: http://home.cmit.net/rwolbeck/programmingtutorial/

That link isn't completely working, but there is a link on the left side. Here is a link to that tutorial directly
http://home.cmit.net/rwolbeck/programmingtutorial/code/FPS%20basic%20example.htm




It should help you quite a bit with some of the basic problems you are having, and also give you a bit more structure to your code that will make it easier to read.

thanks