Is there a way for an object (such as a simple cube for example), to detect a ray sensor hit coming from another object?
not that i know of
use a message actuator and sensor setup.
the object sending out the ray:
the ray is true if it hits the object your looking for right, so have it connected to a message actuator that sends out a message… “hit”. (just make it empty to broadcast, ive never had luck sending the message to specific objects.)
the object being hit:
have a message sensor with the subject “hit”. and have it connected to the actuator of your choice.
now if you have multiple objects that youre looking for, your going to have to have a separate ray and message for each one, because if you hit one it will send the message out to all of them and they will all die, break, disappear, whatever.
that could be solved with a fancy python script
maybe with getHitObject()? i dunno, all of that stuff is way over my head right now. maybe not for you though.
ya but is there a way to have the hit object directly know that it’s hit not through messages
i dont know. Im having a problem with this for my fps. I have many boxes that can break once they have been hit, but i need a seperate ray for each one :S. Ofcourse i could do it that way, but i though maybe there was a way to do it in python that would be better… still not sure if i should wait until im better at python and do that, or if i should just send a million rays out from one empty …
how about on your ray (one ray) have it going into a script
cont = GameLogic.getCurrentController()
own = cont.getOwner()
Ray = cont.getSensors()[0]
if Ray.isPositive():
Obj = Ray.getHitObject()
Obj.Health -= 33
#Where Health is the name of the property that the hit object uses
#As It's Health. And 33 Is How Much To Hurt It
STELLA>
In order to send messages to specific objects you have to include the “OB” infront of the object name, in the “to object” namespace. For example if you want to send a message to a Cube, you would type “OBCube” instead of just “Cube” in the namespace.
Also I am aware of the “getHitObject().getName()” method that can be used to acomplish this with python, but then I might as well just go and set the ray sensor so it responds to several different properties.
As scabootssca said, I was thinking that there might be a built in method to do that.
Oh well, looks like I’m gonna be writing a script after all.
you know, it would be awsome if they included ray detection as a sensor in 2.42
ya i agree
Фф топку.
Script not work, all go to gray wall !
what?
10 letters