The player’s swinging physics that I previously made with Godot’s built-in PinJoint2D was janky and there was no option to change the hook’s string length during runtime. Or, well, at least in an elegant manner. It is technically possible but the game would then need to rely on an implementation detail which is obviously not stable.
With this manually implemented physics, the hook’s string length can be altered freely. The swinging work by snapping the player’s y-axis position to the correct position, given we know the string length and the player’s x-distance from the hook. Linear interpolating the snap makes everything run smoother. The thing is, I wasn’t able to get the kind of swing motion I wanted right away, but I think this works fine as well (and in my opinion looks great too).
TIL: watch out for negative numbers in square root as doing so will result in NaN which won’t be reported to the Godot console.
Log in to leave a comment