My shot-gun won't move with the camera pivot
Blitz3D Forums/Blitz3D Beginners Area/My shot-gun won't move with the camera pivot
| ||
UPDATE: just so you all can see my code and make possible suggestions ;basically pointless Graphics3D 800,600 SetBuffer BackBuffer() ;health Global health = 100 Print "your health is " + health ;fired? Global fired = False Global speed = 4 ;lighting Global light = CreateLight() RotateEntity light,90,0,0 LightColor light,0,0,0 ;collision stuff Global door = 3 Global player = 2 Global scene = 1 Global enemy = 4 ;pivot stuff Global pivot = CreatePivot() EntityRadius pivot,1.5 ;camera Global camera = CreateCamera(pivot) CameraRange camera,1,1000 CameraFogMode camera,1 CameraFogRange camera,60,200 EntityType pivot,player ;weapon ;left barrel Global barrel1= CreateCylinder(32) RotateEntity barrel1,90,0,0 EntityColor barrel1,128,128,128 PositionEntity barrel1,1.5,-1,2.5 EntityParent barrel1,pivot ScaleEntity barrel1,0.2,2,0.2 EntityType barrel1,scene EntityOrder barrel1,-2 ;right barrel Global barrel2 = CreateCylinder(32) RotateEntity barrel2,90,0,0 EntityColor barrel2,128,128,128 PositionEntity barrel2,2,-1,2.5 EntityParent barrel2,pivot ScaleEntity barrel2,0.2,2,0.2 EntityType barrel2,scene EntityOrder barrel2,-1 ;the sky Global sky = CreateSphere(16,pivot) FlipMesh sky ScaleEntity sky,100,100,100 PositionEntity sky,0,50,0 EntityColor sky,0,0,255 ;terrain Global terrain = CreatePlane() ScaleEntity terrain,3,15,3 PositionEntity terrain,0,0,-530 EntityRadius terrain,0.2 EntityColor terrain,0,255,0 EntityType terrain,scene PositionEntity pivot,0,5,0 ;trees? stump = CreateCylinder() ScaleEntity stump,1,7,1 PositionEntity stump,0,-1,30 EntityColor stump,128,64,0 EntityRadius stump,1 tree = CreateSphere(32) EntityColor tree,0,100,0 ScaleEntity tree,3,4,3 PositionEntity tree,0,8,30 EntityType tree,scene EntityRadius tree,3 stump2 = CreateCylinder() ScaleEntity stump2,1,7,1 PositionEntity stump2,10,-1,30 EntityColor stump2,128,64,0 EntityRadius stump2,1 tree2 = CreateSphere(32) EntityColor tree2,0,100,0 ScaleEntity tree2,3,4,3 PositionEntity tree2,10,8,30 EntityType tree2,scene EntityRadius tree2,3 stump3 = CreateCylinder() ScaleEntity stump3,1,7,1 PositionEntity stump3,-10,-1,30 EntityColor stump3,128,64,0 EntityRadius stump3,1 tree3 = CreateSphere(32) EntityColor tree3,0,100,0 ScaleEntity tree3,3,4,3 PositionEntity tree3,-10,8,30 EntityType tree3,scene EntityRadius tree3,3 ;building? bricks = CreateCube() ScaleEntity bricks,19,9,9 PositionEntity bricks,0,9,50 EntityColor bricks,255,0,0 EntityType bricks,scene ;eves eve = CreateCylinder(3) RotateEntity eve,30,0,90 ScaleEntity eve,13,20,13 PositionEntity eve,0,23,50 EntityColor eve,145,72,0 ;door door = CreateCube() ScaleEntity door,3,5,3 PositionEntity door,-6.5,5,43,7 EntityColor door,170,85,0 ;knob of door knob = CreateSphere() ScaleEntity knob,0.8,0.8,0.8 PositionEntity knob,-5,5,40 EntityColor knob,255,255,0 ;the great purple googler! googler = CreateSphere(32) ScaleEntity googler,4,4,4 PositionEntity googler,30,5,10 EntityColor googler,128,0,255 EntityType googler,enemy EntityRadius googler,4 EntityAlpha googler,0.7 ;ammunition bullet = CreateSphere() ScaleEntity bullet,0.2,0.2,0.2 PositionEntity bullet,7,5,2 ;RotateEntity bullet,90,0,0 RotateEntity bullet,EntityPitch(pivot),EntityYaw(pivot),EntityRoll(pivot) HideEntity bullet EntityRadius bullet,1 ;explode boom = CreateSphere() EntityColor boom,255,0,0 EntityAlpha boom,0.5 HideEntity boom ;collisions Collisions player,scene,2,1 Collisions enemy,player,1,1 Collisions player,enemy,2,1 Collisions enemy,scene,2,1 ;loopieness While Not KeyHit(1) If KeyDown(200) MoveEntity pivot,0,0,1 If KeyDown(208) MoveEntity pivot,0,0,-1 If KeyDown(203) TurnEntity pivot,0,2,0 If KeyDown(205) TurnEntity pivot,0,-2,0 ;shooting now! If KeyDown(57) If Not fired fired = True PositionEntity bullet,EntityX(pivot) ,EntityY(pivot)-.5 ,EntityZ(pivot) RotateEntity bullet,EntityPitch(pivot),EntityYaw(pivot),EntityRoll(pivot) ShowEntity bullet End If End If If fired MoveEntity bullet,0,0,speed boomx# = EntityX(bullet,1) boomy# = EntityY(bullet,1) boomz# = EntityZ(bullet,1) HideEntity boom ShowEntity bullet PositionEntity boom,boomx,boomy,boomz End If If EntityDistance(bullet,pivot) >100 HideEntity bullet fired = False End If ;googler movement MoveEntity googler,0,0,0.4 TurnEntity googler,0,1.6,0 UpdateWorld RenderWorld Flip Wend End Function lose() Cls Print "YOU LOSE" End Function |
| ||
Amend 'Global barrel1= CreateCylinder(16,pivot)' to Global barrel1= CreateCylinder(16) After positioning it use (after your 'PositionEntity' command) add: EntityParent barrel1,pivot p.s. you will have to reposition the barrel PositionEntity barrel1,2.5,-1,2.5 will move it into view - then just adjust accordingly. EDIT: ;left barrel Global barrel1= CreateCylinder(16) RotateEntity barrel1,90,0,0 EntityColor barrel1,128,128,128 PositionEntity barrel1,1.5,-1,2.5 EntityParent barrel1,pivot ScaleEntity barrel1,0.2,2,0.2 EntityType barrel1,player EntityOrder barrel1,-2 ;right barrel Global barrel2 = CreateCylinder(16) RotateEntity barrel2,90,0,0 EntityColor barrel2,128,128,128 PositionEntity barrel2,2,-1,2.5 EntityParent barrel2,pivot ScaleEntity barrel2,0.2,2,0.2 EntityType barrel2,player EntityOrder barrel2,-1 EDIT: ps, it is not important to put the 'EntityParent' command after you have positioned the barrel, etc - I just do it that way - you could do it after creating the barrel. I just tend to position and then parent. |
| ||
i found a flaw with the collisions because i was playing around with it because i thought it was cool and noticed when the "shotgun" hits the trees it is pushed back and can end up behind the camera. i don't know why it does that or how to fix it but i thought i would let you know |
| ||
I fixed the collision problem by making the shotguns type scene instead of player, I also added toon shading, now I will add shooting and enemy |
| ||
Another (better?) way to handle a first person weapon is to render it to a seperate (faraway) camera after you have drawn the rest of the scene. Look-up CameraClsMode. This also helps you have better control/handling of the z-buffer. |
| ||
I've updated the origional source code because now I'm having another problem, if you crash into the googler he is solid but if he crashes into you he isn't I have no idea whats causing this shouldnt setting the collisions both ways fix it? |
| ||
Amend Collisions enemy,player,2,1 to Collisions enemy,player,1,1 EDIT: Now you need to set up collisons for the 'googler' and the scenery - unless he is 'ghost-like' and meant to pass through the trees. |
| ||
Thank you again Puki. I updated the code again, I'm open to suggestions, I need to add collision between the bullet and the various things in the level. also I need to add the collision between the player and the googler. I will most likely do that in a couple of hours. |
| ||
i found a flaw with the collisions because i was playing around with it because i thought it was cool and noticed when the "shotgun" hits the trees it is pushed back and can end up behind the camera. i don't know why it does that or how to fix it but i thought i would let you know There is a recursive flag that will give child entities the collision properties of their parents, however, if the Children do not interact with the collision at the same time, they can be 'nudged' around the parent changing their Locally-relative positions. |