# Distance or Collision Sensor?

Which is better:

#all bullets have collision

If bullet.collision_sensor.positive:
do_stuff()

or

def object_dimension(object):
mesh = object.meshes[0]
VertexQty = mesh.getVertexArrayLength(0)
VertexNumber = 0
# get relatively correct distance to target
vxlist = []
vylist = []
vzlist = []

for i in range(0, VertexQty):
vx, vy, vz = object.meshes[0].getVertex( 0, i).getXYZ()
vxlist.append(vx)
vylist.append(vy)
vzlist.append(vz)

#X
smallestx = min(vxlist)
biggestx = max(vxlist)
#Y
smallesty = min(vylist)
biggesty = max(vylist)
#Z
smallestz = min(vzlist)
biggestz = max(vzlist)
#Define dimensions
xdimension = biggestx + smallestx*-1
ydimension = biggesty + smallesty*-1
zdimension = biggestz + smallestz*-1

return [xdimension,ydimension,zdimension]

for bullets in scene's game objects:
for potential_target in scene's game objects:

if bullet.getDistanceTo(potential_target) &lt; bullet.object_dimension().x / 2: #i.e. if dist &lt; bullet width /2:
do_stuff()

*Object Dimension function written by another user named Henry although I can’t remember his exact username, will check on twitter in a bit

Why not raycast?

Not the simple from gun to infinity, but where you raycast each frame the next would be position based on speed vector.

Otherwise, messing with vertices only to get the bounding box seems pointless.

yeah, raycasting based on velocity of projectile is the way to go,

did you see my virtual bullet manager in resources?

I’ve seen some of your stuff on bullets, but the idea came to me because some bullets might not just be a tiny little collision, but rather a big honking circle or something in which case a thin ray cast wouldn’t do the bullet’s scale justice

cast forward from points at edges/corners of front facing sides

I say raycast is the better option.

I guess the sensible size limit to make sense for raycast is arrows/spears.
Past that collision would be simpler.

lol. I use my method for the same thing ur doing. I have a koopa shell that moves (like a big bullet) it has a ray on its left and right, just outside the bounds. this was needed because like u say a central point wont work. the shell would get caught on the wall becasue its corners would drag. so i did it like that, it works great.

let me find the blend. brb

Collisions not always happends, if the speed is to fast it will not register.
A simple raycast is all you need, example:

cast a ray from the center of the camera(or from where you like(bullet)), ray.hitObject then you add an object (sensor->plane) who got a collision sensor then you go trough the hitObjectList and subtract health or whatever.

So i messed with a file and i see what ur talking about. A big object is not going to work with rays. Id say go with distance. that is if ur object is the right shape.

What do you mean with “better”?

What is the criteria you want to compare these things?