I'm new to python code I usually use logic bricks in blender code. I wanted to use python more in my games and I need help in a bit of code. I want it to say that once I collide with an object it will come up with text saying Game Over or Wrong way, etc. Does anyone know how to do this?
I'll give you an example of what you could do.
Add the collision sensor as you normally would, the way you want it, but named "Collision" and set to true pulse triggering, and connect that to a python controller with your script (eg. "Text.py"). You also need a text object, named "Text", with a Game Text Property.
Collision Sensor -----> Python Controller
Then, inside the script (eg. "Text.py"), type the following:
from bge import logic cont = logic.getCurrentController() own = cont.owner sce = logic.getCurrentScene() collision = own.sensors["Collision"] text = sce.objects["Text"] if collision.positive: text["Text"] = "Wrong Way!" else: text["Text"] = ""
Tell me if you need any more help.
Since you are more comfortable using the logic bricks, and this can easily be done with logic bricks, I will use logic bricks.
The Collision sensor is what does it all. I have a "end game plane" with the collision sensor set to only collide with the player's material (you could also use a game property).
When a collision is detected it adds a overlay scene, where I have the text. It also Suspends the main scene (stopping the game play), the two Filter actuators just make the screen turn grey scale and blurred.
Here is my fully working demo. Arrow keys drive the player (cube). Have a look at the HUD scene to see the text and camera.