Many Bullets, Many Enemies (Collision Help)

BlitzMax Forums/BlitzMax Programming/Many Bullets, Many Enemies (Collision Help)

SillyPutty(Posted 2006) [#1]
Hi all

I need advice on how to solve a problem I am having.

I am having problems getting correct collision info using CollideImage

I am returning an array of all objects on the same layer/

So for all bullets I am calling collideimage to test if they collide with any enemies.

My code is shaky at best and when I start adding tests for other objects, results get worse.

Would you suggest I try another method ?

The reason I chose CollideImage and returning the array of objects hit, is that I wouldn't have to check for every enemy for every bullet. CollideImage does that for me.

I didnt want to have to do this: pseudo

for each bullet
for each enemy
checkcollision
next
next

here is my collision code

both bullet and enemy are on layer1.




AntonyWells(Posted 2006) [#2]
Check if their radius intersect, 95% will fail this test, the 5% or so that pass can then use their own single collideimage test.

something like,

local radius# = sqr( ImageWidth(img)*ImageWidth+ImageHeight(Img)*Imageheight)

if radius1+radius2<distance
check more accurately
else
discard
endif


Dreamora(Posted 2006) [#3]
There are other ways:

1. Write all your the actors to the collision layer. If they can only shoot each other, they don't need to read collisions (unless you do movement collision checks in the same step)

2. For all bullets, only read the collision. As bullets most likely can't collide with others, writing them to collision layer will only make collision slower. Now with the read collisions, you can do whatever you want.


3. I would use 2 layers. 1 for enemy and one for you. This way, your bullets only check with enemies and enemy bullets only check with your player. Will greatly speed up the collisions for all enemies (especially if you have situations where you go against enemy masses)


SillyPutty(Posted 2006) [#4]
Thanks so much for your help :)

It is all working now :)