Collision Help

I can’t seem to get any collision detection working… I added a collision sensor to an object, and when I move it around within the game using my arrow keys I want to detect when it touches another object. And whenever that is detected, I want to do some custom python coding which displays some text (I can already display the text, I just need to know WHEN to display it using the collision sensor). How can I accomplish this?

Any help is appreciated.

That is the wrong section, this type of thread this should go in Game Engine>>>Game Engine Support and Discussion.
This section is to ask about the python scripting for addons, scripts, that have nothing to related with the Game Engine.

A .blend would be good or a explain of your setup to better understand what is wrong.

Here is the code I want to call when a collision between 2 objects is detected:

import bge

def main():
cont = bge.logic.getCurrentController()
obj = cont.owner
for i in scenes:
if i.name == “interface”:
interface = i
collision_text = interface.objects[‘collision_text’]

sens = cont.sensors['test']

if sens.positive:
    collision_text.text = 'Collison: True'

main()

Please use code tabs for put the script, that keep the spaces of the code.

That is all the script? because you need to define the “scenes” variable used in the for loop.

Ok, assuming the scenes variable are bge.logic.getSceneList()

There could be a few reasons why the script does not work with you.

1)The bge.logic.getSceneList() only return the scenes already added, so be sure add the scene “interface” as overlay.
2)The scene “interface” needs to be called exactly “interface”.

See the console for know is there some errors, in that file the script work: text.blend (86.7 KB)

I opened your .blend file and I was able to get something similar to work beforehand. My main issue is detecting the collision after I apply a movement to the object with the python code. For instance, here is your same blend file but instead of gravity pulling the cube down, only pressing “x” will cause the object to move down and as a result, no collision is detected. How can we get the collision to be detected after applying a movement, rather than just letting it fall?

text.blend (85.4 KB)