I have some animation problems with Skeleton2D and GDScripting.

I have player holding gun. You can rotate arms UP and DOWN (aim up and down via cursor keys). This is all fine, but i would like also have hands moving while walking (or shooting). As far as i know you cannot "program" IK bone movement for 2D in GDScript. So i have made all the movements in AnimationPlayer. So problem is if i rotate arms UP and them move forward the AnimationPlayer will reset my arms position to keyframe position.

I tried to disable first bone from AnimationPlayer but then whole hand becomes miss aligned (not pointing in the direction it should) probably because the are IK bound. I also tried to add another bone in the middle, but whole structure becomes buggy...

So what i want is independent ARM rotation at shoulders and hands movement/shooting animation. Also i am pretty poor at coding too.

I don't want to make another skeleton because it took me a lot of time to make nice walk, run and other animations :(

thank you

You might be able to do this through script, if you know the offset the arms need. The only issue I can see with doing it through script is that you will have to apply the rotation offset after the AnimationPlayer applies the animation, which I'm not sure how doable that is. Code wise, it applying the rotation to the bone should be something like this:

# assuming bone_node is the shoulder bone node
# and assuming aim_rotation is the rotation you can
# change with the keyboard
bone_node.rotation += aim_rotation

Though as I mentioned, there may be an issue because the AnimationPlayer may override the animation after this code is executed, which would lead to the same issue you are having now.

One possible solution to this is to place the Bone2D you want to rotate as a child of a Node2D, and then rotate the Node2D with the cursor keys. That said, it may require you to redo your animations depending on how it is setup, which is a major downside.

Another solution is to use an IK implementation written in GDScript instead of using the one built in to Godot. The only GDScript IK 2D implementation available that I know of this this IK implementation test by GameEndeavor on GitHub for the game Transmogrify.

I did a quick Google search and it seems there is also this Youtube video by Mizizizi. The video has a link to a Pastebin with the code used for the IK which may be worth taking a look at.

I've written my own IK solvers in Godot, both 3D and 2D, and it isn't too difficult if you want to look into making your own IK solver. I might suggest taking a working IK solver that works in 2D but is written in another programming-language/game-engine and try converting it to Godot if you are looking to make your own IK solver. Like this FABRIK Algorithm (2D) tutorial by Sean on Sean.cm for example.

I would suggest looking into 2D FABRIK IK solvers, as FABRIK is fairly simple to understand and convert to GDScript. I've written a GDScript FABRIK implementation on the Godot demo repository for 3D scenes, and converting it to 2D isn't too difficult, you just have to convert the code to 2D and work around some 2D specific quirks.

I'll keep an eye out for other solutions and will post if I find something else.

Thanx for response.

Yeah adding bone into this is a pain and very buggy. All rotation is overriden by AnimationPlayer.

I will looke the given info, thank you !

I manage to make it work.

I made another AnimationPlayer node with placeholder animation of dummy Node2D. Animation is around 1 sec long and changes Node2D position.y from 0->1->0-> -1->0 so to simulate hand swing. In code under _procces:


	$Skeletal/AnimOscilationHands.play("oscilator2",-1,1)
	var oscilation = $Skeletal/AnimOscilationHands/dummy_oscilator.position.y
				
	arm_front_bic.rotation_degrees += oscilation

For shooting animation i did something similar. I must say it looks better that before.

It needs some fine tuning here and there but it works great !

3 years later