Sonar based turret problems

I was trying to set up a turret script to use later and I seem to come across a problem when trying to get the name of the object that is hit. I was wondering if someone could help me with it. Just see the attached blend. As far as I can tell it should all work well but I’m still pretty new to python.


turret.blend (215 KB)

I don’t have the time to piece together everything which is happening now, but you should open blender in a console, or look at the console output when you’re writing python scripts. For example, on line 34, where you say “town.turretcontrol…”. Delete the “town.” and just have it “turretcontrol.whateveritisyoudohere”.

A useful hint is that you can access a property’s value by saying “own.prop”. So own.prop = 3, if own.prop >= 4 , that kinda stuff. It’ll save you messing with those sensors and actuators you’re using to deal with the booleans.

Also, you don’t have an object called “hitobj”. I’m assuming you want to automatically input the name of the object which the collision sensor detects. For this a “touch” sensor might be better, only because I can see it in the api. sensor.getHitObjectList().

Here’s the api (also available in my sig under GE).

Good luck with this!

Using a ray sensor, you could use something like this:


If not sure if this will help, but you could look at Cyborg Dragon’s Turret Mayhem game: