Is there any way to set up constraints on the joints of the bone hierarchy for the IK, so that the rotation angles would be restricted to some range of angles only and couldn't bend any further?
Also, is there any way to get the information about the relative orientation of the bones programmatically from GDscript?
I'd like to have a series of images in an
AnimatedSprite object for different bend angles and change these frames programmatically depending on how much the joint is bent, so that the sprite's visual bend would (approximately) follow the bend of the bones. Here's an animation explaining this:
The blue shape is the
AnimatedSprite attached to the upper bone and rotates with it. When both bones are in line, it shows frame #1 with straight shape. As the bones rotate past a certain angle, I want to decet that and switch the frame to #2 which shows the bent shape. (There will be several frames for different bend angles.)
Is this possible in Godot?
Here's what I attempted, and it kinda works:
_process() I call
get_rotd() on the node associated with the second bone to get its rotation relative to its parent node (
AnimatedSprite), and then depending on the angle I set the animation frame. When I play the scene, it seems to work as I expected. Now it would be cool if it also worked in the editor so that I could see the frames changing when fiddling with the bones in the
AnimationPlayer (for now I have to switch the animation frames by hand depending on the angle).
tool at the beginning of the script doesn't seem to work, because it prints errors:
<built-in>:13 - Invalid call. Nonexistent function 'get_rotd' in base 'Nil'.
I guess that the variable that stores the bone object is null from some reason :q (I set it in
get_node() - is this the right way to do it when it works as a tool?)