location of a collision?

Blitz3D Forums/Blitz3D Beginners Area/location of a collision?

gerald(Posted 2014) [#1]
Hi,

I want to place an entity at the location of a bullet/tank collision. Where is the collision? It is random as tank is moving and so is player entity. The count collision code allows me to hide the tank entity, translate it, play a sound but I can't work out how to place a "destroyed" entity at the "location".

Do I just put a destroyed entity load after the hideentity code? the collision#,y#,z# looks good for this but I can't work out the collision index.

Help,
Gerald


Yasha(Posted 2014) [#2]
To get the index you need to know the handle of both entities, both the "main" one you're currently trying to use with CollisionX/Y/Z and also the bullet that hit it. Luckily you can get this with EntityCollided.

With that, you can loop from 1 to CountCollisions for the main entity, and check which of them was with the bullet entity you're interested in, using CollisionEntity. That iteration of the loop will be the index you want and can be used with CollisionX/Y/... to get position and normal.


gerald(Posted 2014) [#3]
Hi,

I just used positionx# (bullet(q),1).... This seems to work. If I understand it, the index (1) is the first collision to occur during the current update/render cycle. Unless there are several collisions in the cycle the (1) is the only number available.

I was able to place "health and ammo" at the location of each destroyed entity with this code.

I hate being correct for the wrong reason, using (1), but it works. Unless it crashes or something under circumstances.

thanks,
Gerald


Matty(Posted 2014) [#4]
You can use countcollisions to find out the collision index....iterate through them...better than just using '1'.


gerald(Posted 2014) [#5]
Hi,

I think it is already being used. In the text book example of the shot loop the command count collisions and entity collided are used. So the count collisions has already been called. I even had to be sure to stay in the endif of the loop for the control to work.

Thanks,
Gerald


RemiD(Posted 2014) [#6]
I have never seen a countcollisions equal to more than 1, so i always use the first index, but you may be interested in this post.
http://www.blitzbasic.com/Community/posts.php?topic=101889


gerald(Posted 2014) [#7]
Hi,

I am a beginner when it comes to this, but if a bullet collides with something unless it hits scenery it will almost allways be the first collision with what it is aimed at. As long as it must collide with a gallery it won't react with scenery or whatever.

Gerald