Ai takes no damage problem


(modelinblender) #1

Hello,

I’m not sure what could be causing this problem, but here is the brick setup. I also notice there is no fire effect from a weapon once i restart the game.

I originally did have a health bar for the enemy, but that never worked properly.

Thanks


(Cotaks) #2

we can’t do anything with that screenshot.

cube.001 = what object? bullet, player, enemy?


#bullet?
    collision -> and -> message
                    \-> endObject
#on reciever:
    message -> and - > property (-hp)
            \-> expression (hp < = 0) -> endObject

downside every objects waiting for the message wil subtract hp.
Bricks are not a really good way to set this up (it’s possible)

I recommend to use python for this, then you have a lot more control over anything the player, gun, bullet or anything… does.


(modelinblender) #3

I only know how to use the bricks to do the programming, there is the enemy brick setup. Not sure why it doesn’t remove the AI once damaged enough.


(Cotaks) #4

remove the interval brick, replace it with always -> expression ( robothealth <= 0) - > endObject

so when hp gets to 0 or below end the object


(BluePrintRandom) #5
import bge
cont = bge.logic.getCurrentController()
own = cont.owner

if 'Damage' not in own:
    own['Damage']= 5


ray = cont.sensors['Ray']
if ray.positive:
   if 'Health' in ray.hitObject:
        ray.hitObject['Health'] -= own['Damage']

for doing damage th the person a ray hits

and
Cotaks is right but you can also use a brick for this.

if property health lower than 1---------------and---------------Spawn_Ragdoll - and / or - end own


(modelinblender) #6

Everything I have done in the game engine in the past, was using the bricks, there was some code done in the first file which was done by LS. I made a variation of it last year, not sure why I didn’t press ahead with it, I lost interest in it, just too many effects not there or could work. This upbge may have an effect I could use for a bullet

That was the reason why I used this game engine, I can’t do programming.

I was thinking since I had this open, for a scene focus on a character, then load into a scene as FP, sort of like a cut scene, would it be best to have it seperate? In a different layer I can’t see how else using the bricks, because if the AI goes after the player, it will mean more than program running simualtaneously .


(modelinblender) #7

Not sure what is the problem, I did try -0 and 0.

( robothealth <= 0) - > I tried that as you stated to change the And to expression only loads the detection box of the model.


(modelinblender) #8


(theoldguy) #9

Yup, thats the way I’ve always done it. But I use a small damage script similar to BPR’s along with the expression.
If only one bullet will kill, then you don’t even need an Always, a property will also do.
Property hp (I use hp) equals 1 -----------expression: hp<=0-----------------endobject (actualy I cue the death animation here, but you get the idea)

If youre using a bullet via addobject with collision,( instead of a ray) the game may not detect the collision.
So use a ray, instead. :slight_smile:


(Cotaks) #10

Do you shoot real bullets? if so hook up my bullet script to it, remove anything else, just the script with always(true).

#######################################
#       Bullet script by Cotaks       #
# bullet drop, speed, damage and hole #
#######################################

# put this on the bullet, always(true)
# put a property health on any object.
# Done!

from bge import logic

def bullet_action(cont):

    own = cont.owner

    speed = 340
    damage = 2
    bullet_drop = 0.0015 # higher means faster drop
    hole = 'plasma_hole' #name of the bullethole plane

    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()
    
    #300 is the duration timer (second * 60 so 5 seconds) 
    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])

(modelinblender) #11

I used the firing bullet tutorials on youtube to create them. So an empty, and a bullet in a second layer. If I remember correctly this worked when I first made this file last year.:roll_eyes:

So instead of property use a ray brick?


(Cotaks) #12

ok, put the script on the bullet always-python-module-scriptname.bullet_action
add a plane in hidden layer (for bullet hole) put the name in script.

now if the bullet hits anything it leaves a bullethole, subtracts hp if it got any and kills the object when hp is <=0. and the bullet will drop over time aswell.


(theoldguy) #13

Nice. :slight_smile: