Is it possible to get the value of a property of a collided object?
Yea, through python:
collisionsensor.getHitObject().propname
Is there a way to use only one ray, collision, radar, or near sensor and use it with different properties instead of having more than one sensor to pick up different properties.
Like this:
if ray.isPositive():#to one property
if ray.isPositive():#to another property
Edit: Oh wait. Premature thanks.
It returns the collided object as “None”. Is it supposed to do this?
Hmm, I don’t know how to do that exactly (I never use more than a few raysensors, so I never had the need to do that), however you can just use the object name itself:
if ray.isPositive():
objname = ray.getHitObject().name
if objname == "OBfirstobjname":
# Do for first
if objname == "OBsecondobjname":
# Do for second
.blend please.
There are still errors in your terminal beside that. You have to declare a global variable before you can use it.
Also, you have to actually have the property you’re trying to change present on the object.
if sensor.isPositive():
obj = sensor.getHitObject()
obj.damage += 1 # Prop "damage" has to be on the entity, in order for this to work.
Well, if you run things from the Init scene, it defines all the globals.
I’ve just fixed the return problem. I was using a convex hull for the bounding box when I should have used the box.
Thanks for your help.
you will have to do it like this otherwise you will keep getting errors when there are no objects hit by the ray sensor.
if ray.isPositive() and ray.getHitObject() != None:
objname = ray.getHitObject().name
if objname == "OBfirstobjname":
# Do for first
if objname == "OBsecondobjname":
# Do for second