Problems with Bulletholes

I have reviewed several old forum threads on this subject, but I still can’t get it to work. My problem “seems simple”. I am trying to get bullet hole marks to stick to surfaces as they are shoot. This will be in a driver shooter game, but I am using (trying to use) bullet hole scripts from a FPS game. No matter what I change I just can’t seem to get the bullet hole object to appear. I have added a screen shot to see if anyone sees something obvious.

Thanks

Attachments


Save you python script to a text file and then copy and past it here. The image is too blurry to read.

Here it is.

#bullethole.py

object properties

type name value use

Int ebhole 0 keep track of if I need to position a bullet hole still

random note about implementation:

the gameblender python api give me access to added objects the frame after I trigger the actuator

so I have to react accordingly.

from math import sin, cos, sqrt

vector functions!!

def VEC_length(x):
return sqrt(x[0]*x[0]+x[1]*x[1]+x[2]*x[2])
def VEC_normalize(x):
length = VEC_length(x)
return [x[0]/length,x[1]/length,x[2]/length]
def VEC_cross(x, y):
return [x[1]*y[2] - x[2]*y[1],
x[2]*y[0] - x[0]*y[2],
x[0]*y[1] - x[1]*y[0]]
def VEC_min(x, y):
return [x[0] - y[0], x[1] - y[1], x[2] - y[2]]
def MAT_trackvector(fw, y):
if abs(abs(fw[2]) - abs(y[2])) < .001: #prevent gimbol lock
y.append(y[0])
del y[0]
right = VEC_normalize(VEC_cross(y, fw))
up = VEC_cross(fw, right)
return [[right[0], up[0], fw[0]],
[right[1], up[1], fw[1]],
[right[2], up[2], fw[2]]]
cont = GameLogic.getCurrentController()
obj = cont.getOwner()
ray_sensor = cont.getSensor(“ray_bullet”)
lmb_sensor = cont.getSensor(“fire”)
add_bullet_act = cont.getActuators()[0]

position the last added bullet hole

newobj = add_bullet_act.getLastCreatedObject()
if obj.ebhole and ray_sensor.isPositive():
hit_pos = ray_sensor.getHitPosition()
hit_norm = ray_sensor.getHitNormal()

woohoo!

newobj.setOrientation(MAT_trackvector(hit_norm, [0.0,0.0,1.0]))
pass
newobj.setPosition(hit_pos)
obj.ebhole = 0

determine wether or not to create a new bullet hole

make_bullet = ray_sensor.isPositive() and lmb_sensor.isPositive()
if make_bullet:

I am making the bullet hole, w00t

GameLogic.addActiveActuator(add_bullet_act, 1)
obj.ebhole = 1

I also found a bunch of fun things happening in the “Shortcut” window. (see attachment)

Attachments


Anyone have any thoughts?

I am also having a hard time getting the “near” sensor working. If anyone has any tutorials or blends that they could share I would appreciate it greatly

That error, is the same error. Is it happening everytime you fire? Im guessing here.

In python a variable can only start with a letter or an underscore. So you need to fix that, where ever you use it.

The script never goes past that line, because of the error. (I think) I havent coded in python, but a bit. Im an old school coder, lol.

Then see what errors you get.

In line 37,
3_sensor = cont.getSensor(“ray_bullet”)

ray_bullet needs to be sorrounded by these ( ’ ) not these ( " ), whatever they’re called

No you can use either, to python they are the same.

I found you have to “indent” your scripts by looking at the console in some of my scripts

What itirx said: the variable name can’t start with a letter.

You could however also be having a problem with your indentation.

What I have found is that the internal editor in Blender has trouble when you mix tabs and spaces for the indent blocks. Check to see whether the spacing in front of line 38 is a tab or 4 spaces (or whatever number you use) and then make it whatever the rest of that block is.

To check all your code at once for this, open the script is an external editor (I use IDLE, it should come with the python install). Checking the script for errors should raise any indentation errors (in IDLE: Run > Check Module).

You can fix indent errors by hand or you can fix all of them for the whole script by selecting all your text and doing : Format > Untabify region (or tabify, but I prefer spaces).

Be careful though, because if your code has lots of tab/space errors, then doing this will fix it, but will also cause the places with errors to be indented ‘wrong’ compared to how you want them.