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?