I can’t seem to get any collision detection working… I’m simulating a big xray machine. I added a collision sensor to the couch, and when I move it around within the game using my arrow keys I want to detect when it touches the machine. 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?
Here is the code I want to execute when a collision 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()
Also, here is the .blend file I’m working with. Open it, press “p”, and using the key sets (arrow keys), (w,a,s,d), (z, c), and (i,j,k,l) you can move the couch and the gantry around. I need to determine when collisions occur, which you can clearly visualize by messing around with itcouch.blend (763 KB).
Hello
first, “your Blender” must be in “Blender Game” mode ( top bar)…maybe you already know that?
Then your “collision” object ( Couch mid?), must be ( at least) an “Actor” type one!
Then, add a “Collision Sensor” to it, choose if he will react on a “material” or a “property”, and link it to a “Python” controller; its a basic setup but it should work?
Bye
can you look and try to see what I’m doing wrong? It should open to the game logic editor, with the script open. If you press “p” and move the patient around with w,a,s,d and the arrow keys and try and collide it with the machine, you will see that the collision goes undetected.
I’d really appreciate your help, I have been unable to solve this for a few days now
This is definitely a step in the right direction, thank you! It sort of works for my purposes.
I was wondering though, it seems like the “near” sensor only detects when the origin of two objects are near, is there anyway to detect when any face of an object is near any face of another object? Or would I have to write a script that cross checks each vertex of one object with all the vertices of the other, if that’s even possible?
Hello
sorry, I’m a complete Python illiterate!
My workaround will be to use “planes” ( or separated faces), they have their “origin aligned” to the “face”…I guess?
Bye
The Near sensor creates a collision Sphere around the object with the sensor. It will detect the faces of the other object. You will need to enable Actor though (on the hit Object).
It starts the distance from the object’s centre though, so If your object is 1 m radius wide, and the sensor is set to 1 m, you won’t notice anything.