Many questions about collisions

Blitz3D Forums/Blitz3D Programming/Many questions about collisions

Finjogi(Posted 2005) [#1]
Documentation about collisions are bit.. thin, so could you give suggestions of best practices with them.

Lets start with bullets and targets (both spherical). I want both object removed when they collide.
I assume I have to check collisons both way, bullet to targets and targets to bullet to find exact objects I want to remove.
So, two loops, one checks and removes bullets that have collided to targets and another to check and remove targets that have been hit by bullet. Problem is that second loop gives sometimes "Entity not found" or such errors, because bullets I previously removed.
Ok, workaround was that I flag 'need to be removed' objects and remove them after all collision checks.. so it works ok now.

Is there way to do this kind of bullet/target with one loop and just using one way check "Collisions TYPE_BULLET,TYPE_BALL,1,1" ?
From what I understand problem might be that I could not get ball object(Type) to be destroyed.. just entity.


Naughty Alien(Posted 2005) [#2]
what about linepick at moment when you doing triggering??


Finjogi(Posted 2005) [#3]
Triggering.. you mean instant when I shoot? In that case no, because my bullets move slowly, so I'm interested only real collisions.


jhocking(Posted 2005) [#4]
Ok, workaround was that I flag 'need to be removed' objects and remove them after all collision checks.. so it works ok now.

Not relevant to your current question, but this is a clever trick that would have solved a problem I was having a while ago. I eventually solved that problem by taking advantage of types, using the undocumented Object and Handle commands.


KuRiX(Posted 2005) [#5]
The collisions are detected for "moving objects". So if you can guarantee that the bullets are always moving, then there will be always a collision for the bullets with the balls.

then you can retrieve the ball you have collided with entitycollided.


Beaker(Posted 2005) [#6]
You could just use EntityDistance() for this.


KuRiX(Posted 2005) [#7]
The advantage of collisions over entitydistance is that the collisions will no penetrate the objects, so if the distance is 30, and the balls move at 50, and you are testing for distances < 10, collisions will work and entitydistances not.

Of course entitydistance is faster than collisions


Beaker(Posted 2005) [#8]
You could also try a series of linepicks. One pick everytime the bullet moves, the distance of the movement.


Finjogi(Posted 2005) [#9]
Thanks for replies, linepick and entity distance are nice alternatives and I may use them later on. But back to collision functionality.
Is there way to get 'Type' object that was collided?
Lets say I have two Types and I perform collision checks

Type Target
  Field entity
End Type

Type Bullet
  Field entity
End Type

myBullet.Bullet = new Bullet 
myTarget.Target = new Target
...
For t.Target=Each Target
  If CountCollisions( t\entity )
    If EntityCollided( t\entity, TYPE_BULLET )
      For k=1 To CountCollisions( t\entity )
        If GetEntityType( CollisionEntity( t\entity,k ))=TYPE_BULLET
          ; now I can free Target entity and delete Target object if I wish, but..
          bullet = CollisionEntity( t\entity,k )
          ;
          ; WHAT NOW? I have 'bullet' entity that I can free but how to get Bullet type object that holds that entity?
          ;
        EndIf
      Next
    EndIF
  EndIf
Next
 


I know, my current method works ok but above system could cut half the code load. Am I trying to optimize too much? :)


KuRiX(Posted 2005) [#10]
The easiest but not the fastest:



And why do you need the two if's in the code above?. Just make the for i=1 to countcollisions...


jhocking(Posted 2005) [#11]
The method I alluded to above does just that. I used Handle and NameEntity to store the type object's handle as the entity's name like so:

NameEntity critter\entity,Handle(critter)

(btw, I have a type called 'creatures' with a field called 'entity', and instance of that type called 'critter'.)
Then I could use Object later to retrieve the type object:

critter.creatures=Object.creatures(EntityName(picked))

Note that while this method feels more elegant than the loop kurix posted, I haven't bothered to check which executes faster. I would guess that using Object is faster, but I don't really know.


KuRiX(Posted 2005) [#12]
The Method of jhocking should be faster, because converting a string to integer, and then doing the assignment should be faster than iterating through 100 possible objects...

Of course, for one or two objects, mine is faster xDD