so i have near sensor in my game tied to a small python script.
i have it setup so script always is getting list of objects it is hitting using hitObjectList method. I am looking for object with specific property, as marked by near sensor. i am trying to get a list of all local coins in area of player, but when I run game I get follow effect:
no error in console
list prints as blank
when I change near sensor to search for any objects near it by leaving property box blank, it returns one object is in list. The object is far away, and has the same physics settings as all other objects. My distance and reset distance for sensor is very far… 200 BU and 205 BU. what could be going wrong?
Code I am using:
near = cont.sensors['near']
List = near_sensor.hitObjectList
print(str(obList)) #for debug
if near_sensor.positive:
ob = List[0]
again… this is tied to near sensor named near with true level pulsing on…
If anybody can show me why this is faulting, would appreciate.
Make sure also, along with all the other stuff that has already been posted, the object with the near sensor on it is colliding with the correct collision groups (in other words, make sure the collision masks are for the correct layer in physics panel.)
yes thank you for help! it was actors and collision maskings problems, and with code it was copy paste to forums error :).
now though i have new problems, i link a collision sensor to my script… to handle now colliding with a coin. but it says that the sensor does not exist, even though it has same name as suggested in script, and is linked correctly…
i have also just now tried added more sensors above the error line, and they all work to be added… so it is something i am doing with the Collision sensor!
can collision sensor, no be applied to script on other object like all other sensors i have tried?
i thought maybe space too, but i check and no, it is not the case.
i run print statement, it displays all sensors are connected EXCEPT the Collision…
i even add new sensors, like message, near, and always. they all display, but I add more collisions and it is the same problem. i have infact now tried every sensor type, all work EXCEPT collisions I add… so then this is ether bug, or collision does not work with python controller that is not on different object?
so instead of simply using collision sensor in code, i must use collision to send message to object with python, and connect that to controller instead??
Try opening this Blend and see if it prints all three sensors: collision.blend (486 KB)
It has a python controller and two collision sensors, one on each object. I guess there could be something wrong with your version of Blender but I doubt it.
but now i have one final question… i have collision almost working. now, we i collide… when i hit coins, with logic brick setup of:
Collision -> and -> endObject
it works and detects the collision as soon as coins are hit. but when i connect the exact same collision brick to python, it says it is NEVER positive, despite i am touching same coin in same area… i also try use print statement:
print(str(coins.hitObject))
and it prints “None”, even when the collision works with other logic. i tried now to attach collision brick to both python block, as well as and controller which moves coin on impact. Again a remarkable thing! the coin moves showing a collision, but the python reports there is no hitObject, and that it is never positive! how can this be, it is seeming as if, they are contradicting to each other, yes?