First Person Shooter question

Blitz3D Forums/Blitz3D Beginners Area/First Person Shooter question

Rubiks14(Posted 2004) [#1]
I just got blitz3d and i am new to this site and i'm wanting to make a first person shooter and would like to look at some source, i've looked at the example that came with blitz but i don't really get it. Does anyone know where i can download one that has the source included with it?
thanks Rubiks14


Ross C(Posted 2004) [#2]
I think making a FPS (first person shooter) is a good way to learn blitz. First off start with moving the camera and turning it using the arrow keys. I assume you know how to set up the camera and do basic things like display a cube and turn it?


Rubiks14(Posted 2004) [#3]
yea i can do the basic stuff i just don't know how to like fire the bullets (does it involve alot of math?) and i need to know about like gravity so like to move up and down stairs and stuff like that.....oh and the reason i didn't put FPS is bc of Frames Per Second and First Person Shooter lol


WolRon(Posted 2004) [#4]
You can check out my basic FPS code at my website:
http://home.cmit.net/rwolbeck/programmingtutorial


wizzlefish(Posted 2004) [#5]
Bullets. Easy as pie. No math involved - unless you wanna get complicated. Which I suppose you don't want to do.

Do you know how to use types and sprites? If so, then I can help with the bullets.

If you're using types and sprites, put this code at the top, where all your types are:
Type hole
    Field entity
    Field alpha#
End Type


Then, just put this in your main loop:
If MouseHit(1)
    ammo = ammo - 1 ;subtract ammo (optional)
    h.hole = New hole
    shoot = CameraPick(camera, 400,300)
    h\entity = CopyEntity(bulletholesprite)
    h\alpha# = 0.9
    EntityAlpha h\entity, h\alpha
    PositionEntity h\entity, PickedX(), PickedY(), PickedZ()
EndIf


That will create a bullet. If you want sparks flying out, that's another question - to do with particle engines, etc.

Then, to complete the process, and to optimize speed, you might want to fade out the sprite, so it isn't there all the time. To fade out, just do this:
For a.hole = Each hole
    a\alpha = a\alpha - 0.02
    EntityAlpha a\entity, a\alpha
    If a\alpha <= 0
        FreeEntity a\entity
        Delete a
    EndIf
Next


For gravity, you could use a physics engine if you want to get complicated, which you shouldn't. Or, you could simply put this after "Flip" in your main loop.
TranslateEntity camera, 0, -1, 0


To walk up steps, you could use "EntityRadius" to create a collision radius around your camera. If you have any further questions, feel free to e-mail me.


Rubiks14(Posted 2004) [#6]
thanks u guys for your replies but just a question for optomistic, how would i do a collision check if i used your example up there to see if the bullet hits the guy, would i just use "if imagesoverlap" wait that's 2d


Ross C(Posted 2004) [#7]
He's using a Camera Pick in that example. Basically, it will take the mouse's onscreen position, send an invisible line out and return what it hits. Now, whatever you want to be detectd or collided with, must have been given a pickmode first. Check out EntityPickMode for that.

You can do that for instant hit bullets. Or you can use a line pick. It's like a camera pick, except you define where abouts in 3d space you want it to start from, and the length of the pick. A bit more advanced than camerapick, as faster, as you limiting the length of the pick. The longer the length of the pick, the more time it will take, if it doesn't hit something close.

Just give your enemy a pickmode of 2 i think it is (2 for polygon), and check using PickedEntity() command. This will return the entity "hit" by the pick.

If PickedEntity() = bad_guy then
     ;;;kill bad guy
End If


Whatever you want to happen to the bad guy when he gets shot :o)

The image commands won't help. For bullets the above options are usually best, as blitz doesn't handle two moving entities colliding very well.


WolRon(Posted 2004) [#8]
how would i do a collision check if i used your example up there to see if the bullet hits the guy
Check out my example code and it will answer your question.

Take note to this section:
"Add code between UpdateWorld and RenderWorld to check if any collisions occured between the bullets and anything else. Kill a badguy if the bullet hit one."


Techlord(Posted 2004) [#9]
Checkout Project PLASMA FPS


wizzlefish(Posted 2005) [#10]
That might be a bit over the head of a beginner.


Conan(Posted 2005) [#11]
Um... I wouldn't use linepick or camerapick at all!
I'd just send a tiny sphere really fast and check were it collides. (that's what i'v always done...)

And i've never gotten the so-called problems of the bullet going thru something without detection or anything.

Just my opinion.


Rubiks14(Posted 2005) [#12]
i think that is what i'm gonna do (just send a sphere) seems easiest


Sledge(Posted 2005) [#13]

send a sphere




i've never gotten the so-called problems of the bullet going thru something without detection or anything.



From prior discusion, the pitfalls have been having too high a velocity for one of the entities and/or both entities being simultaneously in motion. I thought someone mentioned that sphere-to-sphere was currently "safe" for the latter scenario so I'd probably start there if I were you, Rubiks14.


Rubiks14(Posted 2005) [#14]
ok


_PJ_(Posted 2005) [#15]
Oh and I found Edzup's FPS code in the archives to work well and be quite easy to use...


http://www.blitzbasic.com/codearcs/codearcs.php?code=365


wizzlefish(Posted 2005) [#16]
Sending spheres will eventually slow down your program. CameraPick is much easier and faster.


WolRon(Posted 2005) [#17]
CameraPick doesn't allow for slow moving projectiles though.


Ross C(Posted 2005) [#18]
Sending shpere won't actually slow your program down over time, unless you not deleting the spheres you send. But moving to moving collisions are unreliable.


jfk EO-11110(Posted 2005) [#19]
It depends on the kind of projectile. If it's a simple firearm, I wouldn't use a sphere, cause if you use the sphere with a realistic speed (eg. 300m/s for a 9mm bullet, or up to 800m/s for .308 rifle ammo), it will not be very useful for collision detection IMHO. In this case I'd use a linepick that "hits" the target immediately, which is much more realistic.

If it's a rocket or some other thrown object, you can use any mesh, and simply use the right collision mode, eg. sphere to poly. But as ross said, as soon as there are two moving things (bullet and target) and they move towards eachother, the collision will be missed unless you do an "updateworld 0" after every entities movement.


wizzlefish(Posted 2005) [#20]
Or, you could exlode the projectile where it lands, and if the explosion was a certain distance from the enemy, the enemy is killed.


Chad(Posted 2005) [#21]
Hey WolRon,
I looked at your code and well, I took away the the commented level and put in my level, and deleted the floor and the box around it, and when I run the code, it's missing a collision with my level, so just fall right through the terrain..

Can you help me with what collision I should use to make it so I don't fall through it?


WolRon(Posted 2005) [#22]
@ Chad

Kind of hard to say without seeing some code.
You really shouldn't hijack Rubiks14 thread. Start your own and post some code so I can take a look at it.


Rubiks14(Posted 2005) [#23]
ok optomistic can u show me how to get the image for the bullets if i do it your way because i can't get it to work and i copy and pasted but i just don't get like how to load my image for it because u said sprite so i did a bmp and i got "entity does not exist" when i ran it

nevermind i figured it out but now i just can't get it to show my bullet hole when i shoot


wizzlefish(Posted 2005) [#24]
It could be hidden behind the wall - I had that same problem, and I tried using "AlignToVector," although that still didn't work - so I still haven't figured out how.


Rubiks14(Posted 2005) [#25]
i got it to work, i had to use entitypickmode


wizzlefish(Posted 2005) [#26]
Aha!


Rubiks14(Posted 2005) [#27]
yea


wizzlefish(Posted 2005) [#28]
Feel free to email me with any more problems.


Rubiks14(Posted 2005) [#29]
ok, what it your e-mail...and also did the entitypickmode fix your shooting


jfk EO-11110(Posted 2005) [#30]
Optomistic try to Turnentity bullethole,180,0,0 after the AlignToVector. And then MoveENtity Bullethole,0,0,0.03 to move it slightly away from the wall (to prevent flickering z-fighting)


wizzlefish(Posted 2005) [#31]
It works now, thanks.