These rays, how does they work for damaging an enemy in a fps?

Ok, im just stuck, i need to know how this ray.getObject thing works.
You know, for damaging enemies in a fps.

I have no clue about these ray based damage systems in the games ive been playing, that were made in blende, and how they works…
But i do know that it has something to do with ray.getObject() and something to lower the health points of the enemy.

So in short: I need to know how to make a enemy (in this case a human) to react to a ray by the player, and lower its health points, using a ray based python script.

So this is a post about a question you will someday ask when you have time?:spin:

Ok, ive got time now.

I have no clue about these ray based damage systems in the games ive been playing, that were made in blender.

I need to know how to make a enemy (in this case a human) to react to a ray by the player, and lower its health points.

(sorry if i explained it badly, im pretty tired)

Ok, i edited the first post, any help would really be apreciated.

ok this is easy. First get the ray sensor, then if enemy health is a property, use this script.


if ray.isPositive():
    obj = ray.getHitObject()
    obj.health -= 1

Hey, is it really that easy?
Cool, thanks kkewley, i know your right, since youve made a good fps before. =)

Though keep in mind that if you’re using 2.49 you’re gonna want to use the new API, so it would look like


if ray.positive:
     obj = ray.hitObject
     obj['health'] -= 1

oh, thanks, man.

Umm, i only get this answer in the console: "name ‘ray’ is not defined…
I got a sensor named “ray”.

Did you bring it into the script with ray = controller.sensors[‘ray’] (or ray = controller.getSensor(‘ray’) if you’re using the old API)

I still cant really get this to work properly.

May i ask for the setup? Im quite rusty now days…

Here’s an example file, just hit space to shoot.

Attachments

rayCast.blend (137 KB)

Ok, this just might be me, but i cant get this to work properly yet, still, if there is some proplems later on, i might write about it here if i cant manage to solve it on my own…