What's up with this?

Why does this command,
pieceimchecking = pieceray.gethitobject()
return nothing? If I print pieceimchecking it prints nothing. Pieceray is a sensor looking for objects with the property piece, all of my pieces on my gameboard have a string property named piece. The sensor is on true level triggering, with a range of one(which should be far enough, since the pieces are at z-0), shooting up the z axis (+ z axis). Whats up with this?

guruhunt

Wow… “piece” overload…
Possibly your problem is that it sends the ray from the object center directly up the z axis. Sorry I can’t check right now, but that’d be my best guess. So try putting a piece directly over the center of the board (I think its the board with the ray sensor) and see if it gets an object.
“piece” out. haha. :slight_smile:

It would print nothing if it hit an object because it returns the object it hit not the objects name. Try doing ‘print pieceimchecking.getName()’ or something.

You don’t need to use getName(), you could just use object.name to get a string. But be aware that adding objects doesn’t changes their names (so you could end up with 8 “OBRedPiece” objects), so it’s better to use the actual object as a reference rather than its name.
In case that doesn’t work, you may need to increase the range of the ray. The raycast distance is measured form the center of the casting object, so if the object is 1u tall, no 1u Z+ ray could see anything. Best to overshoot rays and then calculate the distance betwen the objects than try to make the rays exact.

As Scabootssca said, you’re trying to print the object itself, which is not a printable string.
Also, Python is case sensitive, so “ray.gethitobject()” is not a valid method call, but “ray.getHitObject()” is.
To check if your ray is even hitting anything, try something like this:


if ray.isPositive():
    print "

The Ray hit an object..."
    hitobj = ray.getHitObject()
    hitobjname = hitobj.getName()
    print "Object's name is:", hitobjname

Thanks everyone that’s what I needed to know.

guruhunt