FPS Problems :(

Blitz3D Forums/Blitz3D Beginners Area/FPS Problems :(

DroolBucket(Posted 2006) [#1]
If one of my bullets collides with the level, then all of my bullets are deleted and I can't quite figure out why. Probably a really dumb reason but can someone help?


Function updatebullets()

For b.bullet = Each bullet

MoveEntity b\image, 0, 0, .5 ;move the bullet
EntityParent b\image, 0


;Delete bullet
If EntityCollided(level,bullet_col) Then
FreeEntity b\image
Delete b
End If


Next

End Function

P.S. this game is in its very first stages


Baystep Productions(Posted 2006) [#2]
use [ code ] and [ /code]

Function updatebullets()

For b.bullet = Each bullet

MoveEntity b\image, 0, 0, .5 ;move the bullet
EntityParent b\image, 0


;Delete bullet
If EntityCollided(level,bullet_col) Then
FreeEntity b\image
Delete b
End If


Next

End Function


But your collision check doesn't make sense to me.

You must mean
Function updatebullets()
For b.bullet = Each bullet
MoveEntity b\image, 0, 0, .5 ;move the bullet
EntityParent b\image, 0

;Delete bullet
If EntityCollided(b\image,level) Then
FreeEntity b\image
Delete b
End If
Next
End Function



Sir Gak(Posted 2006) [#3]
Do you initialize a new instance of the bullet type for each bullet (i.e. b.bullet = new bullet)? In other words, is there only one bullet, total, instead of a new one created for every shot going off?


WolRon(Posted 2006) [#4]
Sir Gak, I think he may be trying to use some of my sample code from my website.

DroolBucket, if you are using the code I wrote, it would be easier if you just copied the code I provided in my FPS example line per line into your code, and THEN modify it to suit you, as opposed to the method you appear to be trying now (which is trying to fit my code in with your already written code).


If you break down what you are asking of the computer in this code you wrote:
;Delete bullet
If EntityCollided(level,bullet_col) Then
  FreeEntity b\image
  Delete b
End If
you will find that you are asking it to delete the bullet if ANY bullet (entity type "bullet_col") collided with the level.
What you want is the reverse. You want to find out if the bullet in question collided with the level. To do this, you need to phrase your code like so:
;Delete bullet
If EntityCollided(b\image, level_col) Then
  FreeEntity b\image
  Delete b
End If
Note: replace "level_col" with whatever name it is that you are calling your level entity type.