Still following the same tutorial as I was following so long ago :P
At about 9:30 he mentions using rayCast()
to get the intersection of the ray and any objects with a specific property.
This sounds like what I want to do, which is get the location of the point underneath the cursor on only a specific object.
Here is my script:
from bge import logic
def main():
scene = logic.getCurrentScene()
cont = logic.getCurrentController()
mouse_over = cont.sensors["mouse_over"]
if mouse_over.positive:
tracker = scene.objects["mainTarget"]
crosshair = scene.objects["Cross_hair"]
floor = scene.objects["Floor"]
# tracker.worldPosition = mouse_over.hitPosition
tracker.worldPosition = crosshair.rayCast(floor, "isTrackerFloor", 0, 1, 0).hit
I think it should be working, except I keep getting type errors from the rayCast function arguments. I've tried shuffling them all around, but had no luck (with the above arrangement it throws TypeError: must be str, not int
, which I assume means I have the property name in the wrong place?).
What is wrong with the arguments? and If the above technique doesn't do what I want after all, is there any other way to do this?
object, hitpoint, normal = crosshair.rayCast(floor, crosshair, 0.0, "isTrackerFloor", 0, 1, 0)
, but object, hitpoint, and normal are allnone
(even with the cursor over the correct object)? Plus I only want/need the hitpoint. I also uploaded my .blend, in case that helps. $\endgroup$ – gandalf3♦ May 9 '14 at 19:14