0 votes

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:
In _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).
Simply adding 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 _ready() by get_node() - is this the right way to do it when it works as a tool?)

in Engine by (64 points)
edited by

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.