Files
Leenkx_Examples/animation_movebone/Sources/lnx/MoveBoneIK.hx
2026-05-06 17:52:45 -07:00

29 lines
668 B
Haxe

package lnx;
import iron.object.BoneAnimation;
// Moving a bone - inverse kinematics
class MoveBoneIK extends iron.Trait {
public function new() {
super();
iron.Scene.active.notifyOnInit(function() {
// Fetch armature animation
var anim = cast(object.children[0].animation, BoneAnimation);
// Fetch bone
var bone = anim.getBone("mixamorig:LeftHandIndex4");
// Fetch goal
var tr = iron.Scene.active.getChild("Goal").transform;
var goal = new iron.math.Vec4();
anim.notifyOnUpdate(function() {
goal.set(tr.worldx(), tr.worldy(), tr.worldz());
// Align skeleton to touch the goal
anim.solveIK(bone, goal);
});
});
}
}