First Person Shooter help!!!

Blitz3D Forums/Blitz3D Beginners Area/First Person Shooter help!!!

GIMPY73(Posted 2003) [#1]
does any body have some bullet code for a first person shooter

wot im after is the bullet to start from the end of the gun and shhot towards the gun sight here is my code sofar

Graphics3D 640,480,32,1
SetBuffer BackBuffer()

camera=CreateCamera()
PositionEntity camera,0,1,0

light=CreateLight()
RotateEntity light,90,0,0

gun=CreateCube(camera):ScaleEntity gun,5,5,15
;gun=LoadMesh("deagle.3ds")
PositionEntity gun,30,-40,50
RotateEntity gun,-1,3,-1
EntityType gun,2
EntityParent gun,camera
EntityRadius gun,1
EntityOrder gun,-1

; Create terrain
terrain=CreateTerrain(512)

; Texture terrain
tex=LoadTexture( "wall8.jpg" )
EntityTexture terrain,tex
ScaleEntity terrain,100,100,100
MouseSensitivity# = 2
MoveMouse GraphicsWidth() / 2, GraphicsHeight() / 2
FlushMouse


While Not KeyDown( 1 )

dx# = dx# + MouseYSpeed() / MouseSensitivity#
dy# = dy# - MouseXSpeed() / MouseSensitivity#
If dx# > 85 Then dx# = 85 ElseIf dx# < -85 dx# = -85
xang# = CurveValue#(xang#, dx#, 3.5)
yang# = CurveValue#(yang#, dy#, 3.5)
RotateEntity (Camera), xang#, yang#, 0
MoveMouse GraphicsWidth() / 2, GraphicsHeight() / 2

If MouseDown(1)=1 Then speed#=speed#+.2
speed#=speed#*.9 ; friction
If MouseDown(3)=1
zoom#=zoom#+1
MouseSensitivity# = 6
EndIf
If MouseDown(3)=0
zoom#=zoom#-1
MouseSensitivity# = 2
EndIf

If zoom#<1 Then zoom#=1
If zoom#>10 Then zoom#=10

; Set camera zoom
CameraZoom camera,zoom#

MoveEntity camera,0,0,speed#

xpos#=EntityX(camera)
zpos#=EntityZ(camera)
ypos#=TerrainY(terrain,xpos,0,zpos)

PositionEntity camera,xpos,ypos+20,zpos

MoveMouse 320,240
RenderWorld
mx=MouseX()
my=MouseY()

Oval mx-10,my-10,20,20,0
Plot mx,my

Flip

Wend

End


Function CurveValue#(Current#, Destination#, Curve#)
Return Current# + ((Destination# - Current#) / Curve#)
End Function

any help?

Thanks

GIMPY :)


semar(Posted 2003) [#2]
1) Create an entity (ex a small sphere) at the wanted position - that is, where the bullet should go out from the weapon; use the CreateSphere command.

2) Point the bullet (the small sphere) toward the target, using PointEntity.

3) Move the bullet on Z axis, it will move toward the target; use Moveentity.

You may set the collisions between the bullet and the target, to check if the target has been hit. EntityType, Collisions and EntityCollides would be handy for this task.

Another hint: use a type structure to handle your bullets, so that in the main loop you can manage all the existant bullets - that is, each bullet will have its direction, speed, position, life, damage...

So when you shoot, create a bullet element - note that if you use keydown for shooting, you will create LOTS of bullet, so use keyhit or create a new bullet only every X millisecs:

;type declaration and type pointer
type t_bullet ;the bullet structure
field sphere ;this will hold the entity
field speed# ;speed
end type
Global bullet.t_bullet ;pointer
.
.
If player_has_shooted then
bullet.t_bullet = new t_bullet ;create a new bullet
bullet\sphere = createsphere() ;a sphere as bullet
scaleentity bullet\sphere,0.1,0.1,0.1 ;scale it down unless you want shoot balloons ;-)
positionentity bullet\sphere,x#,y#,z# ;position the bullet at the desired place
resetentity bullet\sphere ;avoid collision when positioning
pointentity bullet\sphere, target ;point the bullet toward the target
endif

;in the main loop
handle_bullet()
.
.
function handle_bullet()
for bullet.t_bullet = each t_bullet ;loop through all the bullets
moveentity bullet\sphere,0,0,bullet\speed ;move the bullet
next


The rest is up to you... have fun !
Sergio.


Sledge(Posted 2003) [#3]
Do you really need an actual projectile? Despite Max Payne, they're still not generally expected and I wouldn't imagine that Blitz'z collision system could reliably determine whether or not fast moving bullets have hit moving targets... which leaves you an extra headache. Isn't this what Linepick is for (especially if you're a beginner)?


GIMPY73(Posted 2003) [#4]
thanks semar ill try ur code out :)

@sledge once i get my head round this ill hide the bullet its just there for visual checking at the mo :)

Thanks

GIMPY :)