attach a gun to the camera

Blitz3D Forums/Blitz3D Beginners Area/attach a gun to the camera

how do i attach a gun to the camera with out entityparent?
I want to have the camera start at a random position and I found out when it is in a new location, the gun doesn't follow...

any help?

Parent the gun first then move the camera. :o)

um, I tried it and it didn't work... do you mean put the code above positionentity camera, or...where?

here is my code, if that helps...
Graphics3D 800,600
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()


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



Global camera2=CreateCamera()
PositionEntity camera2,0,1,-10
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()

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

plane=CreatePlane()
EntityType plane, type_entity 


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


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

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


Global gun2=LoadMesh("guns\\w_fiveseven.3ds")


ScaleEntity gun2,.05,.05,.05
RotateEntity gun2,90,-75,0
EntityParent gun2,camera2

Global 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)

;EntityParent gun,camera




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

PositionEntity gun2,EntityX(camera2),EntityY(camera2),EntityZ (camera2)
;MoveEntity gun2,.1,.04,.3

If JoyHit(6) Then
ShowEntity bullet(t)
EntityParent bullet(t),0

PositionEntity bullet(t),EntityX(gun,1),EntityY(gun,1),EntityZ(gun,1)
RotateEntity bullet(t),EntityPitch#(camera,1),EntityYaw#(camera,1),EntityRoll#(camera,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)


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



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

bulletcount=100-t














RenderWorld 
UpdateWorld 


Text 0,15, "bullets remaining: "+ bulletcount

Text 200,0,EntityX(camera,True)
 Text 200,15,EntityY(camera,True)
 Text 200,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


thanks for the help

Camera = CreateCamera()

Weapon = LoadMesh(Weapon, Camera)
Positionentity, x, y, z


how would I do that and load the mesh?

Does your gun or guns even load? Will it work with two backslashes? If it does, just do what Mortiss said.

It's quite simple, really. Where it says:
weapon = loadmesh(weapon,camera)

Simply input the location of YOUR weapon you want loaded in place of the 2nd "weapon". So in your case, your weapon loading line of code would look like this:
Global gun = Loadmesh("guns\\w_fiveseven.3ds",camera)

Inputting the "camera" after the loading path parents it to the camera.

(Edit)
I just noticed you have your positionentity() call to the location of your gun commented out.

To be more simplistic:


Set your graphics.
Create your camera.
Load your gun.
Position your gun where you want it to be, in relation to the camera.
Parent the gun to the camera.
Move the camera.

Everywhere your camera moves/rotates, the gun will stay in the exact same spot.

ok thanks, When I entityparent the gun to the camera, it is really close, I'm going to try and move it farther away from the camera, thanks