how used getHitObjectList() in the near sensor?

hello for all.
I need to know like being used the function getHitObjectList() in the near sensor
in order to load the data in an own list .

i will create some example but dont work:
it gives back an empty list to me of names objects
thanks for any aid:)

First of all, you don’t need the “iniciarlista” script, because “g.lista” is just a variable to which you can pretty much assign anything from the get go (I mean it’s python, almost anything goes). You don’t need a script to specify that it’s actually a list, before you assign a list to it. So I suggest you get rid of that whole thing.

Second, the python code spat out errors. I don’t know how you got it to do anything else, because you had spaces where they should not be (remember, python notes the whitespace as a delimiter), also I don’t think you need to use “append” here, just assign the list directly to “g.lista”. You can add stuff later to another list, or if you don’t use “g.lista” as an assigment variable (I will use it as such though) then you can probably do it your way too.

I made the following changes to the “nododetector” script:

if cerca.isPositive():
    g.lista = cerca.getHitObjectList()
    print g.lista

Now that returned no errors, but it did return a seemingly empty list “[, , ,]”. I’m just guessing at this point, but I think the whole “getHitObject” thing was not meant to return the actual “names” of the hit object, but rather to give you “access” to the hit object.

In other words; a way to get the hit objects “own”. I hope I’m explaining that right.

However, there is a way to get the names. I don’t think many people know about this (actually I just found it out), but when you ask for the name property, even if you have a property named “name”, the default return for “name” always seems to be the object name in format “OBName”.

So do this, and see what you get:

if cerca.isPositive():
    g.lista = cerca.getHitObjectList()
    count = len(g.lista)
    for i in range(count):
        print g.lista<i>.name

Pretty nifty. I don’t know if this is documented ([I]looks more like a backward hack to me), but I could not find it mentioned in the docs. If anyone has any info on that I would appreciate it (is there 2 sets of python docs maybe? I get the feeling I’m missing some key things)

Well, anyway, hope this helps you out POCHO.

PS: O, and I almost forgot to mention: The object list doesn’t seem to be generated in a consistant order, so I don’t recommend using the order of the returned names to determine what’s closer or farther away from the scaning object.

thanks very much SOCIAL I very happy.
thank you very much by informacion.i working in creating a system simple of artificial intelligence easy to use. With different types from nodes or waypoints .
i learning of your examples :slight_smile: and it modifies them adding a random generator to him .
here is the example modifies:

but to avoid to write all the possibilities of election.
I am trying to use the sensor to near and lists .
here is the example :
but it does not work correctly .:frowning:
you can help to fix it me
thanks for you time and help.:slight_smile:

I think there is some trouble in communication here, due to your bad english. (using spanish for your code doesn’t make things easier either)

I know that you are using my node path AI example (something you should have mentioned in the beginning), but to do what exactly?

Do you want the game object to choose nodes randomly? Do you want it to choose from all the nodes that exist in the gamespace, or just the ones that the near sensor can reach?

You have to give me some details on “exactly” what you want to happen, so that I can write the example you want.

You don’t seem to understand what I told you in my previous post. Get rid of the “inicarlista” script, and the always sensor connected to it, and that python controller as well. You don’t need it, it’s just a distraction that’s taking up space.

The latest .blend you uploaded has errors, check your terminal to see the details.

Your code in there is very, very sloppy. I mean “in range(2 + 6)”, what’s the point of that? Just use “range(8)”. Also, you didn’t think your controll statements through, because you declare certain variables under a control statement itself, and because you use temporary variables to set them they get wiped at the next script pass, so at that point they become undeclared.

Well anyway, as I said, just describe exactly what you want to happen, and I’ll write an example for you.

I apologize .
my idea is create a very simple system of artificial intelligent to used for my games fps.
so that :
we dedicate ourselves single to place different waypoints in our maps, type to counter strike or medal of honor .
types of waypoints :

  • free way : the program randomly chooses between waypoints but near the way to follow (in these I am working now )
    -conditional way :we added in a property within waypoint with the possible routes to follow .

    -holding point :they serve so that the personage waits for a time determined until choosing the following way .
    -concealment point :when our personage is above on those points remains hidden hoping to attack .

it will continue working in it .
sorry for my ingles, i used google traslator for write this texts.:slight_smile:

What do you want the bot to do in “NODOdetectorNEAR.blend” (that last .blend you posted)?

What were you trying to do there that it “didn’t work”?

That’s what I was talking about.

I love this thread you guys
“who’s on first?”

it tried that ours bots moved from a node to another one and when collided with one
to choose between but next a new route randomly. (free way waypoint).

attempt to create something similar to this :

but still I need to much python that to learn

I believe that it goes to be better to work with the sensor ray and getHitObject().
i work some example now.

Ok, it’s a little difficult to understand you (I really suggest you work on your english, try watching american movies with subs in spanish), but anyway, I’ll write some code here that should get you started.

It will basically let the patrollman assign a random node name from a list of objects that have the property “node”. So you can add pretty much anything and not worry about naming it, and writing events for it, and so on:

g = GameLogic
cont = g.getCurrentController()
own = cont.getOwner()


node = cont.getSensor("node") # - scans objects with the "node" prop, makes list.
player = cont.getSensor("player") # - near sensor for "player", the blue guy you move.
nhit = cont.getSensor("nhit") # - detects when bot hits node.


motion = cont.getActuator("motion")
pursue = cont.getActuator("pursue") # - track to
fire = cont.getActuator("fire")


if player.isPositive():
    own.reset = 1 # - so that the code under "else" would run, even if bot isn't on nhit.
    if own.ftimer &gt; 0.5:
        g.addActiveActuator(fire, 1)
        own.ftimer = 0
    if (nhit.isPositive() and own.switch == 0) or (own.reset == 1):
        g.nlist = node.getHitObjectList() # get list
        objcount = len(g.nlist) # - get list lenght
        rand = int(g.getRandomFloat() * objcount) # - set random range to list objcount
        target = (g.nlist[rand].name)[2:] # - Set to pick random from list & get rid of "OB"
        pursue.setObject(target) # - set node name to follow
        if target == own.prevt: # - if random picks same node twice, generate another.
            own.switch = 0
            own.switch = 1
        own.prevt = target
        own.reset = 0
    if not nhit.isPositive():
        own.switch = 0
    own.ftimer = 0

g.addActiveActuator(pursue, 1)
g.addActiveActuator(motion, 1)

Download the .blend.

That’s about all I can do for you. I hope you can use some of it.


thanks very much social.
it will continue working to add other types of nodes .
in order to return but intelligent to bot .

hi SOCIAL I working in example used rayhitobject because the near sensor
crosses the walls .i tried used radar sensor but the same one happens .
finaly i used ray sensor because this dont crosses the walls or objects.
you can download the blend advanced here:(it is no fihish)
you can help me, to make it work like your example
sorry for my bad english. and thanks for you help:yes:

if cerca.isPositive():
g.lista = cerca.getHitObjectList()
count = len(g.lista)
for i in range(count):

 Pretty nifty. I don't know if this is documented ([I]looks more like a backward hack to me</i>), but I could not find it mentioned in the docs. If anyone has any info on that I would appreciate it (<i>is there 2 sets of python docs maybe? I get the feeling I'm missing some key things</i>)

I don’t know if this is a key thing but there is an easier way to do this:

 if cerca.isPositive():
    g.lista = cerca.getHitObjectList()
    for i in g.lista:

Sorry, I know it’s a little off-topic, but I can’t help myself. Anyway it will benefit at least one person.:cool:

Thanks MolFlesH.

Yea, I was overthinking things a bit there.


What exactly is the problem with it? What is supposed to be happening?

hi social
i advanced a litle, but dont work correct yet.:frowning:
sometimes the bot dont find the next node or turn indefinitely .
the last file you can download here:
sorry for my bad english
i am tried to improve my English .:frowning:

How about this:

g = GameLogic
cont = g.getCurrentController()
own = cont.getOwner()


rnode = cont.getSensor("rnode") # Your sweep scanner


motion = cont.getActuator("motion")
pursue = cont.getActuator("pursue") # Track to
rayrot = cont.getActuator("rayrot") # The empty that does the rotation


if rnode.isPositive():
    target = rnode.getHitObject()
    g.addActiveActuator(pursue, 1)
    g.addActiveActuator(motion, 1)
    g.addActiveActuator(rayrot, 0)
    g.addActiveActuator(pursue, 0)
    g.addActiveActuator(motion, 0)
    g.addActiveActuator(rayrot, 1)
# You can't just parent the rotation empty to the bot, because when targets change
# the bot flips around, and then the ray is hitting somewhere else. You can't vertex
# parent either, because that seems to break down the ray sensor. So just have the
# empty copy bot location:

rotobj = rayrot.getOwner()
botpos = own.getPosition()

Download the .blend here: Patrollman_pochray.blend

I hope that can help you out.

Also, I suggest you brainstorm your options before you actually start coding. Really think about things, and try to find the simplest way to do what you want (you can always add stable complexity later). I didn’t look over everything you did, but most of the stuff I could make out didn’t really look necessary.

Just try to plan out your code before you start typing it out.

That said, you are making steady progress, and I’m really glad to see that you are holding on to that.

Keep it up.

thank you very much by your advice
i very happy:)
i can finaly woks my scripts
but I had to write again from the beginning .
you can choose between 3 types of nodes :

green: free way

red: way hopes

blue: restricted nodes

you can download the file here:

I am going to continue improving it

I am going to raise to the file new other post .

Social can you explain how the nodes work? Thanks in advance…

It’s very simple. You just have a rotating raysensor, and depending on what node is hit, (any object with a “node” prop, because that’s what the ray sensor is set to detect) and some related logic, that object is assigned to the “track to actuator”.

That’s the core concept really, everything else is just an add-on to that, or a fine-tune.

If there is anything specific that you have trouble grasping, download the .blend example from my last post, and tell me what that is exactly. I’ll try to explain to the best of my ability.

You could ask POCHO too, if you can figure out his english. Actually reading his code, I think I learned some spanish.


It’s not exactly the way I would have done things, but it works, and that’s what counts.

You did great for your first time. Good job.

hi social
i advanced a litle more on the script :wink:
now in the condicional nodes (BLUE)in the property NODOS
you can write only the NUMBER of the nodes you like choice you bots.
and now you show or hide the nodes with F1 OR F2 KEYS
you can download the example here::slight_smile:
its works fine in the version 2.42a BUT IN THE VERSION 2.43 RC3 THIS SHOW ME IN THE CONSOLE:(over and over again) this menssage:no:
warning btcollisionDispatcher::needsCollision:static-static collision!
warning btcollisionDispatcher::needsCollision:static-static collision!
i dont understand who is this menssage

now i work in example whith character soldier animate and your fps_template example.