FP program does not lower AI bar to change scene

I haven’t a clue as to what is the exact problem with this brick program, it should work. The values aren’t setup properly.

Player

Healthbar

And the ai, now the AI doesn’t cause a scene change if the healthbar for it is lowered using a knifebullet object.

I tried using message damage for both the player and AI, but that doesn’t change anything.

The weapon is a bullet that collides with the AI.

Looking back two years ago, one user mentioned that this

import bge
def bulletMove(cont):
own = cont.owner
speed = own[‘speed’] # float property for motion and ray range
ray = cont.sensors[‘Ray’]
ray.range = own[‘speed’]
if not ray.positive:
own.applyMovement((0.0, -own[‘speed’], 0.0), True)
elif ray.positive:
obj = ray.hitObject
if ‘health’ in obj:
obj[‘health’] -= 5
own.endObject()

This code is best for using for a bullet method collision.

Using a Ray brick. I don’t remember exactly, but a brick program isn’t good for this type of setup.

import bge
def rayShott(cont):
own = cont.owner
start = own.worldPosition
end = own.worldPosition + own.getAxisVect([0.0, 0.0, -50.0])

ray = own.rayCast(end, start, 50, ‘’)
hit = ray[0]
if hit:
if ‘health’ in hit:
hit[‘health’] -= 5

The camera better to use for a collision than an object. Using the python code. :face_with_raised_eyebrow:

import bge
from bge import logic as GL
scene = GL.getCurrentScene()

def CameraShott(cont):

own = cont.owner

mlb = cont.sensors['MouseLB']

if mlb.positive:
    start = own.worldPosition
    end = own.worldPosition + own.getAxisVect([0.0, 0.0, -500.0])


    ray = own.rayCast(end, start, 0.0, '')
    hit = ray[0]


    if hit:
        if 'health' in hit:
            hit['health'] -= 5

def BulletMove(cont):
global scene

own = cont.owner

speed = own['speed']             

ray = cont.sensors['Ray']
ray.range = own['speed']

if not ray.positive:
    own.applyMovement((0.0, 0.0, -own['speed']), True) 
elif ray.positive:
    obj = ray.hitObject
    
    if 'health' in obj:
        obj['health'] -= 5  
        own.endObject()   

The bullet fires too far

if you want to have an interface for the player’s health, armor and weapons readings, the best way to do this is to use python and not message methods in logical bricks, since bricks are very limited - all you need is to get a list of scenes and find the desired scene by its name in it and make changes with its interface

scenes = bge.logic.getSceneList()

def player_hud(cont):
own = cont.owner
for scene in scenes:
if scene.name=="Player_HUD_Scene":
health_bar = scene.objects['player_health_bar']
health_bar.playAction("Health_Bar_Action", own['health'], own['health'])

text_health = scene.objects['Text_Player_Count']
text_health['Text'] = str(own['health']) # if you use text objects for counters health, armor, bars
#you transfer only the player's data to the interface scene - his health, armor, endurance, and you do not need to try to add data from computer-controlled units to this transfer - they should only cause damage to the player and the player himself will transfer his data to the interface scene

No,

I’m just trying to get the knife weapon to end the AI and load a scene. When I look back somebody who did some python for the original file, didn’t use bricks because it wasn’t very good at doing the task.

I looked back at my inbox, and noticed the message I sent and left that file. I tried, because of the setup of the old file I had at the time, nothing worked, so I gave up on it. Until recently that is.

I may need to create another healthbar for the AI, but that basic one is okay for the moment, it is more the game completing and ending is the problem, so the weapon effect uses a bullet called knife, and it fires out of an empty on the player’s weapon.

Previous video shows exactly what is happening. It wasn’t loading before.

your problem is inhere:

def CameraShott(cont):

own = cont.owner

mlb = cont.sensors['MouseLB']

if mlb.positive:
    start = own.worldPosition
    end = own.worldPosition + own.getAxisVect([0.0, 0.0, -500.0])


    ray = own.rayCast(end, start, 0.0, '')
    hit = ray[0]


    if hit:
        if 'health' in hit:
            hit['health'] -= 5

In very simple words:
It only works when you click the mouse button.

The health check is done when mlb.positive. So health is never being removed unless you click on the exact same time as the bullet hits the target.

//edit
Here is my origional bullet script. Remove everything you have that removes health/deals damage. and put this script on the bullets

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

# put this on the bullet, always(true) -> python-module -> scriptname.bullet_action
# 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])

if you don’t want a bullet hole, then remove every line with hole in it and that function bullet_hole completely.

Now you have real speed and calcualtions, health will be removed, now it’s up to you to figure out how you want to change the scene.

//edit 2
here a blend file, run it and hit spacebar to shoot, 5 times to kill the cube.
bullet script preview.blend (575.5 KB)
(upbge 0.2.5)

I’ll try the code by Villi89

Is this in the correct direction?

Is there a need for a Ray brick to connect with the Left moust button brick for the bullet?

I can remove the arm actuator brick from the brick setup. That doesn’t do anything. :roll_eyes:

The collision with the AI and player still brings both health bars down. Only the bullet can bring down the health of the AI.

Just an up to date clip

As for removing any bricks relating to the AI and player health does that apply with the code used as an example.

Bullet code for the bullet object. The property for the bullet is knife, so in the code where is that edited?

def BulletMove(cont):
global scene

own = cont.owner

speed = own['speed']             

ray = cont.sensors['Ray']
ray.range = own['speed']

if not ray.positive:
    own.applyMovement((0.0, 0.0, -own['speed']), True) 
elif ray.positive:
    obj = ray.hitObject
    
    if 'health' in obj:
        obj['health'] -= 5  
        own.endObject()   

And the AI damage bricks are not connected. The code needs to register the health going down on the AI and the player’s code is done by python.

I think I’m getting there slowly with this. :face_with_raised_eyebrow: