FPS Code glitch?

Blitz3D Forums/Blitz3D Programming/FPS Code glitch?

Guy Fawkes(Posted 2010) [#1]
Can someone help me make it so that this code shoots an infinite number of bullets each mouse press, and shoots them where ever the camera is pointing, instead of in 1 position all the time?



also, i wanna draw a "bullet hole w/ blood" in the "body" of the "target", how would i get the position of where the bullet hit?


Who was John Galt?(Posted 2010) [#2]
This is from memory of B3D, I don't have it here to test.

1. You need to create bullets and add them to a list, rather than using 1 bullet.
2. Your updatebullets needs to loop through the list and update each one, instead of referencing 1 bullet.
3. You need to move the bullet entities in the direction the camera is facing when they are fired, presumably? I think you can use the TFormVector(?) command to create a unit vector pointing in the same direction as the camera when each bullet is fired. Store this vector in the bullet that is created, and add the vector to the bullet position each frame. You can scale the vector by a constant value to control the speed of your bullets.


Guy Fawkes(Posted 2010) [#3]
by that, u mean



Am i close, if not, where did i mess up and how can i fix it?


Drak(Posted 2010) [#4]
Again, it's not a glitch. There are NO glitches. Code only does what it's programmed to do.

To make a bullet, use your code in the above post. When you want to fire a shot, grab the player's xyz coordinates. Then, position the bullet there. Next, orient it with the camera. I use

PositionEntity(b\entity, EntityX(player,1),EntityY(player,1),EntityZ(player,1)
RotateEntity(b\entity, EntityPitch(camera,1), EntityYaw(camera,1),EntityRoll(camera,1))


Then, every frame move the bullets forward on their z axis.
For b.mybullet = each mybullet
     MoveEntity(b\entity, 0,0,b\bulletspeed#)
Next


As far as getting perfect collisions, you can use CollisionX, CollisionY, and CollisionZ to grab global coordinates of where your bullets hit anything. That though, is a different topic.

FYI, applying HideEntity b\entity will not allow the bullet to respond to collisions. If you're looking to make your bullet invisible, use EntityAlpha() instead.

Edit: John's idea would work too, but if you're trying to cut down on math just position it and orient it with the camera. :)


Guy Fawkes(Posted 2010) [#5]
ok, how is this so far? i want to learn what to correct, and what not to correct.

this is what i have so far:




Who was John Galt?(Posted 2010) [#6]
No cigar.

My suggestions covered two main points:

1. Iteration through a list of bullets.
2. Use of TFormVector function.

Your 'attempt' doesn't include either of those things, so it's not really an attempt at all. Did you actually read my suggestion?

Assuming you read my post as soon as it was written, you expended all of 12 minutes' effort to read it, code your 'attempt' and respond with your post.

Try again. I want to see the use of Eachin to iterate through your list, and use of TFormVector. Also, there is no creatbullet function in your code, so how can it run?


Guy Fawkes(Posted 2010) [#7]
EDIT:

I WAS going to update that post, but since u posted before me, here's what i have so far:




Guy Fawkes(Posted 2010) [#8]
i simply need to know what u mean by 'list of bullets' cuz thats as close as ill get unless i know what it is


Guy Fawkes(Posted 2010) [#9]
here's what i have so far. although im getting a mav....




Guy Fawkes(Posted 2010) [#10]
I figured it out! Would somebody help test this?! =D\




Yeshu777(Posted 2010) [#11]
Try..


Function UpdateBullet.mybullet()
	For b.mybullet = Each mybullet
		If b\entity <> 0
	EntityAlpha b\entity,1
	b\bulletspeed# = 0.1
;	PointEntity b\entity,playercube   ; comment this out
	MoveEntity b\entity,0,0,b\bulletspeed#
EndIf




GIB3D(Posted 2010) [#12]
I made this to try out some bullet code. It moves the bullet forward and checks for a collision and if it finds a collision, the bullet gets deleted. If you try it and think that the bullets get created and just float there, you'd be wrong. They're updating really fast ;)




Guy Fawkes(Posted 2010) [#13]
why is each bullet going faster? and how can i use free entity on each bullet that collides instead of hideentity?




GIB3D(Posted 2010) [#14]
After you use FreeEntity then set b\entity to 0 and just check if entity > 0


Guy Fawkes(Posted 2010) [#15]
ok, that solves the free entity part, but what about the speed > each time a new bullet is created and "shot" part?


Guy Fawkes(Posted 2010) [#16]
actually, that doesnt solve the free entity part.

i cant figure out why when it collides w/ the target, it gives me a mav saying it isnt there...

i need it to delete each bullet after being collided OR it gets too far out then i need it to delete the bullet




Ross C(Posted 2010) [#17]
You really don't want to be using free entity with bullets. it's much faster to hide them then reuse them.


GIB3D(Posted 2010) [#18]
Well if you free the entity and then try to access it later you will get an error.


Drak(Posted 2010) [#19]
You can FreeEntity() them. It works fine. After you free it, you no longer want to do anything with it. Place the Exit command after FreeEntity() to make sure you don't try to reference a bullet that isn't there. So long as you only iterate through your bullets one time per game loop you won't have any problems.


Naughty Alien(Posted 2010) [#20]
..download this file and unzip it anywhere on your hard drive..then just load and run FPS.BB file and enjoy..here is everything you will ever needed for setting up FPS, including motion, weapon, bullets, bullet holes(or explosion traces), etc..all media included...I hope it helps..enjoy..

arrow keys motion, mouse looking, mouse left button fire

file is here

http://www.easy-share.com/1909568931/rcfps.zip


Ross C(Posted 2010) [#21]
No, i mean, it's loads faster to recycle bullets, than freeing them, then copying them when you want a new one. Much more efficent too.


_PJ_(Posted 2010) [#22]
Less chance of accidentally acessing a NULL type too that way. :)


Guy Fawkes(Posted 2010) [#23]
i agree