Plays Help to shoots

Blitz3D Forums/Blitz3D Programming/Plays Help to shoots

Blackeffekt(Posted 2007) [#1]
Hi,
I´m a beginner in B3D.
Hir is the Code (I can not so good English I come from Germany)
Graphics3D 640,480
SetBuffer BackBuffer()
Dim Ball(100,4)

SB = LoadSprite("S.bmp"):HideEntity SB
SpriteViewMode SB,4
HandleSprite SB,0,0
EntityAutoFade SB,100,1000
ScaleSprite SB,20,30

cam = CreateCamera()
MoveEntity cam,0,10,-20
EntityType cam,1
CameraClsColor cam,0,128,255

;Plane
Plane = CreatePlane()
Tex1 = LoadTexture("Tex1.bmp")
ScaleTexture Tex1,40,40
EntityType Plane,2

EntityTexture Plane,Tex1


While Not KeyHit(1)
Collisions 1,2,2,2

XM# = MouseXSpeed()
YM# = MouseYSpeed()

TurnEntity cam,0,-(XM#/3),0,True
TurnEntity cam,(YM#/3),0,0

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

If KeyDown(200) Then MoveEntity cam, 0,0,0.5
If KeyDown(208) Then MoveEntity cam, 0,0,-0.5

If MouseHit(1) Then
Schuss = Schuss + 1
If Schuss = 101 Then Schuss = 1
Ball(Schuss,0) = 1
Ball(Schuss,1) = EntityX(cam)-10
Ball(Schuss,2) = EntityY(cam)
Ball(Schuss,3) = EntityZ(cam)+10
Ball(Schuss,4) = CopyEntity(SB)
EndIf

For I=0 To 100
If Ball(I,0) = 1 Then
MoveEntity Ball(I,4),Ball(I,1),Ball(I,2),Ball(I,3)
Ball(I,3) = Ball(I,3) + 1
EndIf
Next

UpdateWorld
RenderWorld
Flip
Wend
End

Whwn I shoot then shot appears somewhere else. Waht have I made wrong? Thank you for the answers


b32(Posted 2007) [#2]
The command 'MoveEntity' should be 'PositionEntity':
PositionEntity Ball(I,4),Ball(I,1),Ball(I,2),Ball(I,3)
-----
EDIT:
-----
Wait .. erm .. thought that was an easy solution, but I was wrong.
First, keep the spriteviewmode standard, so place a ";" comment for the line:
;SpriteViewMode SB,4

Then, when firing, use:
PositionEntity Ball(Schuss,4),EntityX(cam),EntityY(cam),EntityZ(cam)
RotateEntity Ball(Schuss,4),EntityPitch(cam),EntityYaw(cam),EntityRoll(cam)

To place the (new) bullet at the same position as the camera, and rotate it in the same direction as the camera.

Finally, use:
MoveEntity Ball(I,4),0,0,1

To move the bullet.
This means that you don't need Ball(Schuss,1/2/3) anymore.


Blackeffekt(Posted 2007) [#3]
Thanks for the answer. It has helped very much