can someone help me with this code?

I want to put one more edit object actuator to make another bullet hole but i dont know how to make it, the blend file is here to download too( this blend is not mine is from social I think).
Please help i think that is not too complicated for you guys.

import GameLogic as GL
from Mathutils import Vector
cont = GL.getCurrentController()
own = cont.owner
POP_OUT = 0.01 # So that the bullet hole is not “in” the actual normal

Sensors

mouse_click = cont.sensors[“mouse_click”]
ray = cont.sensors[“ray”]

Actuator

spawn = cont.actuators[“spawn”] or cont.actuators[“spawn2”]
if mouse_click.positive and ray.positive:

Get required info

pos_vec = Vector(ray.hitPosition)
normal_vec = Vector(ray.hitNormal)

Make the bullet hole

spawn.instantAddObject()
bullet_hole = spawn.objectLastCreated

Rotate and position

bullet_hole.alignAxisToVect(normal_vec.xyz, 2, 1)
normal_vec.magnitude = POP_OUT
bullet_hole.worldPosition = (pos_vec + normal_vec).xyz

came on help me, Its not hard at all for you guys and l dont know how to make it , i try and have no result…
Is just a simple change, not ll take more than 10 minutes of your lifes, please help me

How do you want the script to decide what bullethole object to use?

thank god someone, With this script I just can use one object to make the bullet hole that is a plane with a texture that is on the second layer i want to put another plane with texture, use other actuator but the problem is the script need a specific actuator’s name to make the bullet holes (spawn is the specific name of the actuator).
I want to know how to put on the code a new actuator with a diferent name, like spawn2 for example.
I hope that you get it, if you need more details dont exitate in ask.
Thanks


spawn = cont.actuators["spawn"] or cont.actuators["spawn2"] 

The problem with what you have in this line is you are trying to assign two actuators to a single name, and somebody please correct me if I’m wrong, but that can’t be done.

You would need another ‘object’ to be the second actuator. Like this:


 spawn = cont.actuators["spawn"] 
spawn2 = cont.actuators["spawn2"] 

Then you could decide which one you want to use and add it like the one you have.

no it not work, I have tryed this, and I just try it again but is something more to make it work
Thanks for try

Try this:

bullethole = GameLogic.getCurrentScene().addObject( “objectname”, owner )

Owner isn’t important in this case; the object you add is added at the owner’s position, but since you’re moving it right away, that doesn’t matter.
Replace objectname with the name of whatever object you want to spawn - if your bullethole objects are called ‘bullethole0’, ‘bullethole1’, ‘bullethole2’, you could do this:

At top of script -

from random import random

…later…
bullethole = GameLogic.getCurrentScene().addObject( “bullethole” + str(random()*4), owner )

Then each bullethole will be a random shape.

vicenti, you are italian or brazilian? because of the name?
And thanks a lot for help me but, I m very noob on python, can you explain me if I have to replace other line of the code or something like that?
the import from import ramdom i understand the problem is the other things…(im a idiot)
Please give me a hand here.

Please just pu the things togheter, I tryed to put the code in a lot of places but dont work, help!

Is this more like what you wanted? I’m sorry, but I’m having trouble understanding exactly what you want the code and the actuators to do.
I’m assuming you want to use two different bullet hole objects, and if that’s the case, hopefully this helps.

Attachments

BulletHole[EDITED].blend (50.2 KB)

I’m American. :o

Try this:

import GameLogic as GL
from Mathutils import Vector
from random import random
 
cont = GL.getCurrentController()
own = cont.owner
POP_OUT = 0.01 # So that the bullet hole is not "in" the actual normal
 
# Sensors
mouse_click = cont.sensors["mouse_click"]
ray = cont.sensors["ray"]
 
# Actuator
if mouse_click.positive and ray.positive:
 
 # Get required info
 pos_vec = Vector(ray.hitPosition)
 normal_vec = Vector(ray.hitNormal)
 
 # Make the bullet hole
 bullet_hole = GameLogic.getCurrentScene().addObject( "bullethole" + str(int(random()*2)), owner )
 
 # Rotate and position
 bullet_hole.alignAxisToVect(normal_vec.xyz, 2, 1)
 normal_vec.magnitude = POP_OUT
 bullet_hole.worldPosition = (pos_vec + normal_vec).xyz

Just create two objects named ‘bullethole0’ and ‘bullethole1’, and you should be all set.

thanks, Im very happy that you guys give me a hand, thanks very much!!!

Without altering that script, could it be used in Blender 2.48a? If altering and converting is needed, could someone do that, please?

Anyone who know a video on this? plz help:spin: