hitPosition always returns 0,0,0 over one of my objects

Hi Python people!

Making a game and I’ve got this script I borrowed from https://www.youtube.com/watch?v=-IeNnw6zzvQ

I have a dynamic object called “tracker” which is a invisible triangle the character follows around. The idea is to move this “tracker” with the mouse and then the character will follow.
the “tracker” object has a MouseOverAnySensor that ideally will have either the ground material or property “terrain”(see below) so the character can only walk on the ground, but is disabled for now.
and a LeftButtonMouseSensor that is set to tap.

I have a static object called “terrain” which is a giant mesh, with node materials , linked from another .blend file, and a property(currently an integer) called “terrain”

I’ve got this script that is triggered by the “tracker” sensors.

from bge import logic

def main():
    scene = logic.getCurrentScene()
    cont = logic.getCurrentController()
    mouse_over = cont.sensors["Mouse_over"]
    mouse_click = cont.sensors["mouse_leftclick"]
    if mouse_over.positive and mouse_click.positive:
        tracker = scene.objects["tracker"]
        tracker.worldPosition = mouse_over.hitPosition
        print("tracker at: ",tracker.worldPosition,".")
        print("mouse at: ",mouse_over.hitPosition,".")

I put the print statements in to try to figure out whats happening…

When I run the thing:
If I click on the “terrain” object, nothing happens.
If I click on any other static object, the hitPosition returns the correct position.
if I inverse the Mouse_over sensor, thus causing it to fire when the mouse is not over the object, and click on the “terrain” object, hitPosition returns 0,0,0, which is incorrect.

Here’s the kicker. I have another version of this same “game” where this tracker thing works. Since then, I have:
-upgraded my kernel which caused me to have to upgrade blender to 2.79
-decimated the terrain and applied location rotation and scale to it and to a bunch of other objects.
-futzed with parenting on some objects that follow the tracker so my characters pants stop floating away.
-rearranged my materials so they are more organized and faster and unfortunately less pretty.
-relinked in all my “city” objects which magically fixed some missing textures.
-done who knows what with logic bricks to add functionality.
-worked on some menu’s that setup and start the game.
-started implementing sound.

Full disclosure: I get the following error message when I run the game.

Warning, sensor “Property” has lost a link to a controller (link 1 of 1) from object “envoy button”
possible causes are partially appended objects or an error reading the file,logic may be incorrect

this is regarding another object that is not really related, except possible that it does have a MouseOverSensor and a MouseLeftButtonSensor.

:spin:I just can’t fathom what is going on. I’m not sure the mouse sensor is working and I can’t figure out why the hitPosition is always returning 0,0,0 when the “terrain object” is clicked. It seems the mouse cannot sense the static “terrain” object.

Anyone have any ideas on how to get this to work or ideas to investigate further?

oh I don’t know if this is helpful, but I have a “menu” scene wtih game menues, like load, new, options, etc. and have a mouse look actuator on it.
when I go to the “main” scene(where the game is) I put in another mouse look actuator to turn the mouse on. So I don’t know if this is relevant, but I’m trying to provide as much info as possible.

Is the mouse over sensor in the terrain object?
if not it should be, or alternatively use mouse over any*

Thanks for a great idea!
The sensor is attached to the “tracker” object and I am using Mouse Over Any.

I did try putting it on the terrain, and now it returns 0,0,0 for every object clicked on.

I feel there is something weird going on.

Here is a possible weird thing. I noticed in the version that works, the physics tab is grayed out on the “terrain” object because it is linked. In the version that doesn’t work, physics is not grayed out and can be edited. Something to do with what is local or not, I don’t know. Anyway, I don’t know if that helps anyone, but I feel more info is good.

I found the problem.

When I was cleaning my materials, I also wanted to speed things up a bit, so I was madly turning material and texture settings off. I guess if you turn off Material Physics on the thing you are clicking on, it breaks this script. What exactly the problem is, I don’t know. I suppose the mouse sensor might not respond to such objects or hitPosition is dependent on physics. I don’t know. Anyway…

I turned Material Physics on and it solved this problem.:D:D

yes, for future reference, raycasting is reliant on physics…that is where the ‘hit’ comes in :slight_smile: