Collision Detection for bullets

Blitz3D Forums/Blitz3D Beginners Area/Collision Detection for bullets

xtremegamr(Posted 2008) [#1]
I'm making a (VERY) simple FPS, and I just figured out how to make the player shoot bullets. Now, I want to be able to shoot a bullet at an enemy, and have that enemy die. The only problem is, I don't know how to do collision detection between the bullet and enemy. Could someone help me?


Ben(t)(Posted 2008) [#2]
try something like this


if entitycollided(enemy, bullets) then
enemyhealth#=enemyhealth#-(5?)
endif

I use a different collision type for my shots to make everything simpler


xtremegamr(Posted 2008) [#3]
I tried that already; the bullet passes through the enemy, but has no effect on the enemy.


Aoneweb(Posted 2008) [#4]
I use NGC for Blitz, saves a lot of programming, and works well.


Whats My Face(Posted 2008) [#5]
You might want to just line pick and see what the bullet hits and just not use the bullet for collision detection its what I usually do.


xtremegamr(Posted 2008) [#6]
I have no idea how to do entity picking. I tried the blitz help file things, but I still don't get it. Could you post some code or something? Thanks.


Dreamora(Posted 2008) [#7]
Use LinePick, correct.
Use the current position and the position from the frame before and use those for the linepick command. radius is the one of the bullet.

you just need to make the objects that can collide pickable, thats it.


xtremegamr(Posted 2008) [#8]
So I would do this, right?
-------------------------
If LinePick(bulletx , bullety , bulletz , lastbulletx , lastbullety, lastbulletz , bulletradius) = enemymodelhandle then

delete enemy
delete bullet

End If


chwaga(Posted 2008) [#9]
i dont know how to use linepicks, but it sounds like the error in your current collision-detection system is that you bullet could be traveling too fast, and as a result, between frame 1 and frame 2, it goes right through the guy!


Stevie G(Posted 2008) [#10]
Blitz collisions prevent penetration to the bullet can travel as fas as you like.

For the linepick , you don't have to worry about last position. Assuming your bullet is pointing in the direction it's firing, you can use something like ..

tformvector 0,0,BulletSpeed, Bullet, 0

If LinePick(bulletx , bullety , bulletz , tformedx , tformedy , tformedz , bulletradius) = enemymodelhandle 
  delete enemy
  delete bullet
else
  moveentity bullet, 0,0,bulletspeed
endif



Terry B.(Posted 2008) [#11]
Did you remember to put a collision command at the begining of the code?


Ross C(Posted 2008) [#12]
Remember, the second x,y,z co-ords in the linepick are NOT the end co-ords, they are distances from the start x,y,z co-ords.


xtremegamr(Posted 2008) [#13]
I tried that LinePick thing, and it still doesn't work. Is there anything else about linepicks I should know able.


mtnhome3d(Posted 2008) [#14]
if you don't like linepicks you could do a camerapick and check the z value to see if fits in your bullet range.


mtnhome3d(Posted 2008) [#15]
CameraPick cam,400,300
p_e=pickedentity()
p_x=PickedX()
p_y=PickedY()
p_z=PickedZ()
if p_z<100 and p_e=enemyhandle then freeentity enemy


Whats My Face(Posted 2008) [#16]
heres some an example thats completely done using camerapick

Graphics3D 800,600,16,2 ;set up graphics

;create a box to shoot
Local box = CreateCube()
PositionEntity box,0,0,5
EntityPickMode box,2 ;set its pick geo

;create a camera
Local cam = CreateCamera() 

HidePointer(); hide the mouse
While Not KeyHit(1)
	
	If MouseHit(1) Then 
		If CameraPick(cam,MouseX(),MouseY()) = box Then ;check if the user shot the box
			Text 400,300,"YOU SHOT THE BOX"
			Flip
			Delay 1000
		Else
			Text 400,300,"YOU MISSED THE BOX"
			Flip
			Delay 1000
		EndIf
	EndIf 
	
	;update and render stuff
	UpdateWorld()
	RenderWorld()
	
	;draw a pointer
	Oval MouseX()-6,MouseY()-6,12,12,False
	Line MouseX(),MouseY()-7,MouseX(),MouseY()+7
	Line MouseX()-7,MouseY(),MouseX()+7,MouseY()
	
	Flip
Wend