blood effect code

Hi,

I got a copy of this from a tutorial on how to create a blood effect, I have the object working, but the code here, I don’t know what to change or remove, I did try one edit with it.

It was from a tutorial similar to the sparks effect.

The object is blood1 so that should load similar to the way I did the sparks, so I setup a ray2 gun is now fpgun.

From those who know how to program, what exactly is relevant?

##############################################################
#Blender 2.5 bullethole script
 
#this script is free to use and is under no license agreement.
 
##############################################################
 
from bge import logic as GameLogic
from mathutils import Vector
c = GameLogic.getCurrentController()
scene = GameLogic.getCurrentScene()
own = c.owner
         
space = 0.3

gunspawn = scene.objects['gun spawn']

# sensors
Ray = c.sensors['Ray']
Ray2 = c.sensors['Ray2']
fpgun = c.sensors['fpgun']
m24flare = c.sensors['m24flare']

# actuator
ground_hole = c.actuators['bullet_hole']
body_hole = c.actuators['blood_hole']
ground = c.actuators['ground']
blood = c.actuators['blood1']

if Ray.positive and fpgun.positive and gunspawn['equipped'] == 2 or Ray.positive and m24flare.positive and gunspawn['equipped'] == 1:
    # Get info
    
    pos_vec = Vector(Ray.hitPosition)
    normal_vec = Vector(Ray.hitNormal)
         
    # make object
    ground.instantAddObject()
    bullet_hole = ground.objectLastCreated
   
   # position hole
    bullet_hole.alignAxisToVect(normal_vec.xyz, 2, 1)
    normal_vec.magnitude = space
    bullet_hole.worldPosition = (pos_vec + normal_vec).xyz
   
    ground_hole.instantAddObject()
    bullet_hole2 = ground_hole.objectLastCreated
         
    bullet_hole2.alignAxisToVect(normal_vec.xyz, 2, 1)
    normal_vec.magnitude = 0.003
    bullet_hole2.worldPosition = (pos_vec + normal_vec).xyz

if Ray2.positive and glockflare.positive and gunspawn['equipped'] == 2 or Ray2.positive and m24flare.positive and gunspawn['equipped'] == 1:
    
    # Get info
    pos_vec = Vector(Ray2.hitPosition)
    normal_vec = Vector(Ray2.hitNormal)
         
    # make object
    blood.instantAddObject()
    bullet_hole = blood.objectLastCreated
         
    # position hole
    bullet_hole.alignAxisToVect(normal_vec.xyz, 2, 1)
    normal_vec.magnitude = space
    bullet_hole.worldPosition = (pos_vec + normal_vec).xyz
    
    # make object
    body_hole.instantAddObject()
    bullet_hole3 = body_hole.objectLastCreated
         
    # position hole
    bullet_hole3.alignAxisToVect(normal_vec.xyz, 2, 1)
    normal_vec.magnitude = 0.003
    bullet_hole3.worldPosition = (pos_vec + normal_vec).xyz

Is it right that you want the blood splatter like an bullet hole where you shoot.

I think in that case depends on life and/or person or object you hit?

first:

you have to check if all sensors and actuators are still on the object you load the script from (cont.owner) (owner of the controller mostly an Python one)

second:
all sensors has to be the same name or you have to change it in the script

instandAddObject not sure if it still working this way maybe has to replaced to scene.AddObject(obj, pos, life_time)

No bullet holes, I only want the blood splatter effect. So I imagine that and one ray2, I guess, and an edit object with blood.

I am not sure what you want to create?

test code: is it this?


from bge import logic
from mathutils import Vector
c = logic.getCurrentController()
scene = logic.getCurrentScene()
         
space = 0.3

ground = scene.objectsInactive['Plane']

Ray = c.sensors['Ray']
fpgun = c.sensors['fpgun']


if Ray.positive and fpgun.positive:
    pos_vec = Vector(Ray.hitPosition)
    normal_vec = Vector(Ray.hitNormal)
         
    # make hole1
    bullet_hole = scene.addObject(ground, None, 50)
   
    # position hole1
    bullet_hole.alignAxisToVect(normal_vec.xyz, 2, 1)
    normal_vec.magnitude = space
    bullet_hole.worldPosition = (pos_vec + normal_vec).xyz
    
    # make hole2
    bullet_hole2 = scene.addObject(ground, None, 50)

    # position hole2 
    bullet_hole2.alignAxisToVect(normal_vec.xyz, 2, 1)
    normal_vec.magnitude = 0.003
    bullet_hole2.worldPosition = (pos_vec + normal_vec).xyz



you need an obj called Plane or rename it to blood in an inactive layer, also two objects one with an property name it by your self and an “player” the owner of the script with this sensors all connected to the python controller:

Ray: as Ray: with the given property of the other obj should be always activated (look after the right axis!)
Keyboard: as fpgun: you can set every key but you should use the “tab” trigger controller

maybe you want to create an blood splatter all over the place where the hit is landing?
did you have an picture?

I’ve created everything I need for the moment, I just need the exact code that creates a blood load in effect once an AI has been shot. So the name of the object that is animated is called bloodeffect.

There aren’t any bullet holes.

Here is a screen, so blood is the name of the brick as seen on the edit object, then I have a ray2 so blood is the property on the blood object in another layer. And there is the code you edited. I did add the blood sensor.

Attachments