So I am attempting to make one cube shoot and hit a specific enemy in front of it among several. My cube has a ray sensor and a keyboard sensor as well as a message actuator. I have been wandering around the documentation for the game logic module and know a fair bit about the options available for scripting in the BGE for these logic bricks.
My thought was that my cube would use the ray sensor to identify which enemy it was shooting at and then send a message to that specific enemy telling it that it had been shot. Then each individual enemy would have a different reaction to that message when it was shot: one would jump, one would run off, another would fall over.
However, my understanding is that the message cannot programatically be sent to a specific object (only an object with a property with the given name) nor can the KX_GameObject value be sent in the body of the message (must be a string).
What am I missing in order to achieve my goal?
Thanks All…
I’m pretty much trying to find out the same thing, but the only thing i can think of so far is to give each enemy a different property name, an create loads of logic bricks for each one. Seems too complicated, there must be an easier way of doing it. I’ll let you know if I ever find out!
Why don’t you use the hitObject variable of the ray sensor?
cont = GameLogic.getCurrentController()
the_ray = cont.sensors['your ray sensor name goes here']
shoot_key = cont.sensors['your keyboard sensor name goes here']
if the_ray.positive and shoot_key.positive:
dead_guy = the_ray.hitObject
Then put code here to cause something to happen. You might, for instance, use the state system and activate a dead state. or, you might have a boolean property on the enemy called “dead” which you set true like this:
Thanks blendenzo, I am an admirer of your site. That is exactly what I came up with independently, oddly only moments after your post twilight zone-ish So ya I have my enemy waiting for its enemy property to change with a property sensor which triggers a python controller and then an actuator.