i am using rayCast to find if there is a roof over my character’s head, but it only returns a tuple thing, and i can’t use rayCastTo, because it stops at one object.
all i want is the name of the object that it returns, how do i get rid of the other parts of the property?
any help would be greatly appreciated.
use [0] to get the first item.
so:
ray_object = obj.rayCast( cube, obj, 0.0, “blueTeam”, 1, 1, 0)[0]
or you can do:
ray = obj.rayCast( cube, obj, 0.0, “blueTeam”, 1, 1, 0)
ray_object = ray[0]
use [1] for the second thing etc…
ray_hit_point = ray[1]
You can find a list of the things returned by raycast here:
http://www.tutorialsforblender3d.com/GameModule/ClassKX_GameObject_21.html
so:
Returns the game object[0], the hit point[1] and hit normal[2] (poly = 0)
or
Returns the game object[0], the hit point[1], hit normal[2] and polygon[3] (poly = 1)
thanks heaps
I’ve also found that a star operator is useful for unpacking an entire tuple in one step:
ray = obj.rayCast( cube, obj, 0.0, "blueTeam", 1, 1, 0)
ray_object, ray_hit, ray_normal = *ray
See:
http://docs.python.org/tutorial/controlflow.html#unpacking-argument-lists
Edit:
Oops… this does not work. :S
It doesn’t work because you put a star in there. The line should read
ray_object, ray_hit, ray_normal = ray