Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Ramito |
For my game I want a spaceship to become a kinematic body when docking so other spaceships won’t knock it off.
This works but when going back to a regular rigid body I experience some glitches, either the position or velocities reset to incorrect values. Trying to resolve this I ended up with the following implementation (I revert the mode to rigid body in the regular _physics_process
call when not docking):
func _integrate_forces(state):
if !dock_locked && dock_state == 0: return
mode = RigidBody2D.MODE_KINEMATIC
position = state.transform.get_origin()
linear_velocity = state.linear_velocity
var impulse = 0.9 * (dock_position - position) - 0.2 * linear_velocity
state.apply_central_impulse(impulse)
state.integrate_forces()
# print_debug(impulse)
My issue is the above works quite well if the print_debug statement is uncommented! If I uncomment the print statement my spaceship smoothly snaps to the position I want and as soon as docking is interrupted it maintains momentum correctly and keeps moving as normal.
But if I comment the debug print the ship stops moving in place while docking.
Can anyone explain this and help me understand what do I need to do to get the behavior I need consistently?
Thanks!
I just stumbled on exactly the same problem.
I was going through a very simple tutorial, and noticed a problem with basic game loop. Debugging led me to discover what you did: print
statements change program behavior. I get correct behavior with them and invalid behavior with print statement deleted or commented out.
I also notice that presence of print
statements seems to impact whether debugger breakpoints around it activate or not (?!?).
Stranger yet, adding multiple print
statements in a row seems to affect program execution as well, each time in a subtly different way. That’s literally the only thing I change.
This is very concerning. It’s the most basic of programs, and already the parser is doing something weird and buggy. It’s the kind of thing that makes one drop the engine entirely.
What is known about this issue?
Santa | 2021-12-20 01:18
I stopped worrying about this a while back (as longa s my builds work).
I do not think it’s a parser/compile issue, though. I still think it’s a race condition, or in other words, a physics threading issue.
I have not tested on recent builds, but I am hopeful it will be fixed… eventually!
Ramito | 2021-12-20 07:04