0 votes

Morning all

I am stuck at making IK work through script. Hoping for some help. I will include the script and the order of nodes below.

FPS[Spatial]
    -Armature[Spatial]
        -Skeleton
            -FPS Mesh
            -SkeletonIK
            -Target[Spatial]
        -AnimationPlayer

I tried the https://www.youtube.com/watch?v=TfAO2W6lO8E by RandomMomentania and https://godotengine.org/article/skeleton-inverse-kinematic by Andrea Catania.

I can make the mesh deform by manually moving the target in the editor. However - I am hoping to make it happen through script so that I can either move the target in the script
or change the targetnode of IK during runtime, to help with picking a different weapon and having the hands moving to new holding location based on the weapon. However, when I try to change the target node or when I move the current targetnode either by changing globaltransform or globaltransform.origin - no mesh deform happens. I can still play the animation and that works as expected.

What am I doing wrong?

extends Spatial


onready var iktarg=$Armature/Skeleton/target_1

func _input(event):
    if Input.is_key_pressed(KEY_UP):
        iktarg.global_transform.origin.y+=0.1
    elif Input.is_key_pressed(KEY_DOWN):
        iktarg.global_transform.origin.y-=0.1

    print(iktarg.global_transform.origin)

    if Input.is_key_pressed(KEY_SPACE):
        $AnimationPlayer.play("push")

Thanks all

in Engine by (89 points)

Not to answer my own question but the SkeletonIK needs to be started and then run when modified in code. At least that helped my situation. In the following code, I have Skeleton with SkeletonIK and two spatials P1 and P2 as it's children.
Hope this helps someone

extends Spatial

var cur=1


func _ready():
    $Armature/Skeleton/SkeletonIK.start(true)


func _input(event):
    if Input.is_key_pressed(KEY_SPACE) and not event.is_echo():
        if cur==1:
            $Armature/Skeleton/SkeletonIK.set_target_node($Armature/Skeleton/p1.get_path())
            $Armature/Skeleton/SkeletonIK.start(true)
            cur=2 
        else:
            $Armature/Skeleton/SkeletonIK.set_target_node($Armature/Skeleton/p2.get_path())
            $Armature/Skeleton/SkeletonIK.start(true)
            cur=1

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 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 webmaster@godotengine.org with your username.