Code example old FPS file Ai walk to player hint?

Where would I put that code?

In findplayer.py

Where abouts in it?

So this shows the bricks that are in the code, named.

So how does this particular AI in another layer loaded via an empty find the player using navmesh.001

‘walk’ brick named a steering brick

Then there is ‘runC’ as another steering brick

all logical blocks are limited by the fact that they are compiled into code at the start of the game - and then, if they are not connected to python scripts, they perform only what they are designed for this is a one-time search on the navigation mesh (possibly permanent if you do not set self terminated), but it is 100% not an opportunity to change the navmesh agent or create advanced logic, it is 100% a huge pile of logic bricks in which even the author will get confused after a week if he did not work on the game this is 1000% of the inability to influence logic blocks in the game (they are compiled and you do not have access to them through other logic blocks). At one time, I taught python from Mike Dawson’s book - We program in python and diligently taught the bge/upbge API and also taught examples written using python - just understand one thing no one will do the game for you (especially writing the logic of finding the path and agent behavior) you should start writing everything yourself. and finally, the easiest way to connect the code that I showed you is to always connect the sensor to the script controller (module) and to the steering actuator

this simply example for pathfinding for UPBGE v.0.2.5 maybe this help you, if not help - learn python and API blender game
simply_pathfinding_steering.blend (121.2 KB)

First I am not a programmer, so I’ve posted here to try and edit somebody’s else’s blend file, the code is all there, how difficult can it be for the AI to find the player with a navmesh somewhere else, it doesn’t need to be put in the code or does it, the screen shows the brick, so why is there a brick when there is the code?

mavmesh.001 is in the top section of this file, used in blender 2.78, not upbge.

Just to give a better view, here is the navmesh, it could be that you are thinking I mean a massive whole area.

And this is the old mesh, or original, once the player gets down to the area, the enemy is activated by a sensor object, and the code is being read by the program, and all of that stuff going on…

import bge

cont = bge.logic.getCurrentController()
scene = bge.logic.getCurrentScene()
own = cont.owner

#self
self = scene.objects[own.name]

#properties
target = own['target']
incover = own['incover']
direction = own['direction']

#sensors
pnear = cont.sensors['Pnear']
collide = cont.sensors['Collision']
Ray = cont.sensors['Ray']
delay = cont.sensors['Delay1']
shootray = cont.sensors['shootray']

#actuators
refind = cont.actuators['State1']
attack = cont.actuators['State2']
flare = cont.actuators['flare']

#steering
findc = cont.actuators['walk']
runc = cont.actuators['runC']

#cover object
cover = scene.objects[own['target']]

#animations
runAnim = cont.actuators['run']
duck = cont.actuators['duck']

fwd = cont.actuators['fwdwalk']
back = cont.actuators['backwalk']
left = cont.actuators['walkleft']
right = cont.actuators['walkright']

fwdfire = cont.actuators['fwdwalkfire']
backfire = cont.actuators['backwalkfire']
leftfire = cont.actuators['walkleftfire']
rightfire = cont.actuators['walkrightfire']

#sound
sound = cont.actuators['sound']

#path finding
if cover['cover'] == 'safe' and pnear.positive == True and Ray.positive == False:
    findc.target = str(own['target'])
    cont.activate(findc)
    if direction == 'Run Forward':
        cont.activate(fwd)
    elif direction == 'Run Backward':
        cont.activate(back)
    elif direction == 'Run Left':
        cont.activate(left)
    elif direction == 'Run Right':
        cont.activate(right)

if cover['cover'] == 'safe' and pnear.positive == True and Ray.positive == True:
    findc.target = str(own['target'])
    cont.activate(findc)
    if direction == 'Run Forward':
        cont.activate(fwdfire)
    elif direction == 'Run Backward':
        cont.activate(backfire)
    elif direction == 'Run Left':
        cont.activate(leftfire)
    elif direction == 'Run Right':
        cont.activate(rightfire) 
        
elif cover['cover'] == 'safe' and pnear.positive == False:
    runc.target = str(own['target'])
    cont.activate(runc)
    cont.activate(runAnim)

#flare
if pnear.positive == True and Ray.positive == True and delay.positive and shootray.positive == True:
    cont.activate(flare)
    own.sendMessage("Phit", "", "player")
    cont.activate(sound)
elif pnear.positive == True and Ray.positive == True and delay.positive and shootray.positive == False:
    cont.activate(flare)
    cont.activate(sound)
    
#find new cover   
elif cover['cover'] != 'safe':
    cont.activate(refind)

#cover found
if collide.positive == True and incover == '':
    if collide.hitObject.name == str(cover):
        cont.deactivate(findc)
        cont.activate(duck)
        cover['cover'] = 'used'
        own['incover'] = 'cover'
        cont.activate(attack)

Movecover.py contains the steering brick code?

So how does enemy008 find the player? Using navmesh001 so what is the problem here?

Thanks.

`import bge

cont = bge.logic.getCurrentController()
scene = bge.logic.getCurrentScene()
own = cont.owner

#self
self = scene.objects[own.name]

#properties
target = own['target']
incover = own['incover']
direction = own['direction']

#sensors
pnear = cont.sensors['Pnear']
collide = cont.sensors['Collision']
Ray = cont.sensors['Ray']
delay = cont.sensors['Delay1']
shootray = cont.sensors['shootray']

#actuators
refind = cont.actuators['State1']
attack = cont.actuators['State2']
flare = cont.actuators['flare']

#steering
findc = cont.actuators['walk']
runc = cont.actuators['runC']

#cover object
cover = scene.objects[own['target']]

#animations
runAnim = cont.actuators['run']
duck = cont.actuators['duck']

fwd = cont.actuators['fwdwalk']
back = cont.actuators['backwalk']
left = cont.actuators['walkleft']
right = cont.actuators['walkright']

fwdfire = cont.actuators['fwdwalkfire']
backfire = cont.actuators['backwalkfire']
leftfire = cont.actuators['walkleftfire']
rightfire = cont.actuators['walkrightfire']

#sound
sound = cont.actuators['sound']

#path finding
if walk['runC'] == 'safe' and pnear.positive == True and Ray.positive == False:
    findc.target = str(own['target'])
    cont.activate(findc)
    if direction == 'Run Forward':
        cont.activate(fwd)
    elif direction == 'Run Backward':
        cont.activate(back)
    elif direction == 'Run Left':
        cont.activate(left)
    elif direction == 'Run Right':
        cont.activate(right)

if cover['walk'] == 'safe' and pnear.positive == True and Ray.positive == True:
    findc.target = str(own['target'])
    cont.activate(findc)
    if direction == 'Run Forward':
        cont.activate(fwdfire)
    elif direction == 'Run Backward':
        cont.activate(backfire)
    elif direction == 'Run Left':
        cont.activate(leftfire)
    elif direction == 'Run Right':
        cont.activate(rightfire) 
        
elif cover['cover'] == 'safe' and pnear.positive == False:
    runc.target = str(own['target'])
    cont.activate(runc)
    cont.activate(runAnim)

#flare
if pnear.positive == True and Ray.positive == True and delay.positive and shootray.positive == True:
    cont.activate(flare)
    own.sendMessage("Phit", "", "player")
    cont.activate(sound)
elif pnear.positive == True and Ray.positive == True and delay.positive and shootray.positive == False:
    cont.activate(flare)
    cont.activate(sound)
    

#cover found
if collide.positive == True and incover == '':
    if collide.hitObject.name == str(cover):
        cont.deactivate(findc)
        cont.activate(duck)
        cover['cover'] = 'used'
        own['incover'] = 'cover'
        cont.activate(attack)`

I changed some of it, am onto something close to my objective.

Now that is movecover.py, which is all about the AI hiding and then moving, and firing.

It must be findplayer.py

So the objective is Ai finds player, and then Ai will attack player using animation and I will need to add some sort of damage for that.

But first thing is first, need the AI, any Ai to find the player within that navmesh001 that is the aim. My first attempt at adding a new item failed, then the second was a new AI, none of the examples from blendswap worked, so I have to use what is there, and perhaps texture it differently. For now it will have to do. :expressionless:

I think the AI needs a point in order to go somewhere, with the example of cover, within the navmesh area.

Where the empty is for enemy 008.

Now the second point, on the stairs. So the AI should go to the second one

I have tried the file, but the Ai doesn’t go to the first cover point.

The AI loads, animated, and fires within a certain range of the player.

I did also try adding four objects in a new copy of the file, only for it to freeze. From my old file, I used one AI in a diferent area not connected with the first. Not sure, if that is because the file is over 70mb. 84mb is the release file, so there is no real difference.

But yes, why doesn’t the existing ai not move from one location to the next, it should no? :confused: Ai is located from an empty, loads in from a layer, and should walk to go up there stairs there. Navmesh is there. That was the main change in the demo file I have made, two months ago.

Hi, your uDrop link shows “File not found”.

You are correct, not sure what happened there. The actual file is available on youtube.

I’d have to upload at some point again, the newer file, or the similar one.

I want to get the Ai to find the player, my other task is to get the other AI to find the player, as it has a sensor, it should animate once in contact with the player. I want that to cause damage to the player. In another file it animates, but in this one, it doesn’t. I am not sure why that is.

Is the navmesh the problem? It can’t be, if it is, where in the code does it state navmesh, it doesn’t as the navmesh brick is there in the file, linked, but no actual mesh selected.

That I don’t know what that is about or how that works.

Here is the older file clip

And the more recent file, so you see one works, but doesn’t, the other works, but doesn’t. So half and half. I find the Ai with the hand weapon of use.

The Ai doesn’t work in that area. It could be another reason, the stair case isn’t easy for the Ai to navigate.

I setup a cube, used steering brick and mesh. So that sort of works in that area.

It has some sort of use. I could use something else as an alternative for now. :nerd_face: