According to @Daedalus_MDW
Here is an example:
from bge import logic
def bullet_action(cont):
own = cont.owner
player = own.scene.objects['player']
if player['active_weapon']:
if not 'weapon_data' in own:
weapon_data = player['weapons'][player['active_weapon']]
own['weapon_data'] = weapon_data
speed = own['weapon_data']['bullet_speed']
damage = own['weapon_data']['bullet_damage']
bullet_drop = own['weapon_data']['bullet_drop']
hole = own['weapon_data']['bullet_hole']
distance = speed/logic.getLogicTicRate()
own.applyMovement([0,distance,-bullet_drop], 1)
y_vec = own.worldOrientation.copy().col[1]
y_vec.magnitude = distance
end_vec = own.worldPosition.copy() + y_vec
ray = own.rayCast(end_vec, own.worldPosition.copy(), 0)
if ray[0]:
if 'health' in ray[0]:
ray[0]['health'] -= damage
if ray[0]['health'] <= 0:
ray[0].endObject()
bullet_hole(cont,ray,hole)
def bullet_hole(cont,ray,bullet_hole):
own = cont.owner
own.endObject()
bullet_hole = own.scene.addObject(bullet_hole, ray[0], 300)
offset = ray[2]
offset.magnitude = 0.001
bullet_hole.alignAxisToVect(ray[2], 2, 1)
bullet_hole.worldPosition = ray[1] + offset
bullet_hole.setParent(ray[0])
If you want to use this you need to alter some things in the script, should be easy with a tiny bit of python knowledge.