Thanks for the extensive answer, Monster. I’ll do my best to return the favor.
First of all excuse my apparently lousy example-.blend, my initial post was one of those frustrated-latenight-posts, that should better be written after a few much needed hours of restorative sleep. My apologies.
It was never my intention to seed confusion, I was talking about the scenario, when the two objects are close to each other but not intersecting or touching. My understanding is that “player.rayCastTo(target)” casts a ray from KX_GameObject player’s center (represented by Suzanne) to the KX_GameObject target (small cube), ignoring only the mesh of player and returning the first object it hits on its way, which can be the target, meaning there is no other object in between. Looking at it this way, I feel it should never return None.
Your guess, that the rayCastTo() is somehow called before the target’s change of position seemed to be true at first, but if I first place the target next to the player, and then behind one of the obstacles, it should print “None” first and “target” second, as it would alsways be one step behind, but it prints “None”, “Obstacle”, so it does seem to physically change the position before the ray is casted. This is what keeps me awake at night and forces me to write badly thought-out threads.
Using rayCast() instead of rayCastTo() doesn’t help.
About the remarks:
When I start a new project, I usually make a concept file, where I try to get the seemingly most difficult part to work first. As a result I switch stuff around a lot and try many things and don’t really spend much time on meaningful yet concise naming, that normally happens, when I’m more or less convinced, that I can accomplish everything and start a new file to rebuild just what I need in a cleaner way.
- About True Pulse and Tap: That’s definitely right. I should have switched them back off. Thanks.
-
objs: I know about the dangers of setting objs once, as you assumed correctly, it’s just for testing.
-
render.showMouse(True) - I don’t really see the problem here.
[INDENT=2]A) it sure is documented.
B) the mouse cursor showing up seems to be a pretty good indicator, that it is indeed performed.
C) I think it is only called once, not at the game start, but for testing, I felt it would be sufficient, if the cursor shows up as soon as the mouse moves. The script is run in module mode, so:
The main level code (indentation 0) gets executed the first time the module is accessed.
Source[/INDENT]
- about the two comments: Sorry, just my hopeless tries to help strangers understand the code.
- more, smaller functions: In general I would say amen, brother, but is it really necessary to write a new function to get the first element of a tuple? I think a comment would be enough here.
*Added new comments with remarks to think about. They can be removed after you decided how to continue.
- I’ll think about them, thanks for the permission to delete them.
Wow, that actually was fun. I hope you don’t take this the wrong way, I do appreciate your effort towards clean and understandable code and didn’t mean to be monstrous:p. I promise improvement. Thanks for taking the time to look into this and write such a long answer.
To sum it all up, I still can’t understand, why I don’t get the expected behavior and rayCastTo() returns None sometimes. I hope somebody can shed some light on this.
One Love,
Jay-D