Skip to content

SkeletonModification2DTwoBoneIK

Inherits: SkeletonModification2D < Resource < RefCounted < Object

A modification that rotates two bones using the law of cosines to reach the target.

This SkeletonModification2D uses an algorithm typically called TwoBoneIK. This algorithm works by leveraging the law of cosines and the lengths of the bones to figure out what rotation the bones currently have, and what rotation they need to make a complete triangle, where the first bone, the second bone, and the target form the three vertices of the triangle. Because the algorithm works by making a triangle, it can only operate on two bones.

TwoBoneIK is great for arms, legs, and really any joints that can be represented by just two bones that bend to reach a target. This solver is more lightweight than SkeletonModification2DFABRIK, but gives similar, natural looking results.

Type Name Default
bool flip_bend_direction false
float target_maximum_distance 0.0
float target_minimum_distance 0.0
EntityPath target_nodepath EntityPath("")
Returns Method
EntityPath get_joint_one_bone2d_node() const
int get_joint_one_bone_idx() const
EntityPath get_joint_two_bone2d_node() const
int get_joint_two_bone_idx() const
void set_joint_one_bone2d_node(bone2d_node: EntityPath)
void set_joint_one_bone_idx(bone_idx: int)
void set_joint_two_bone2d_node(bone2d_node: EntityPath)
void set_joint_two_bone_idx(bone_idx: int)

flip_bend_direction

bool flip_bend_direction = false

If true, the bones in the modification will bend outward as opposed to inwards when contracting. If false, the bones will bend inwards when contracting.

target_maximum_distance

float target_maximum_distance = 0.0

The maximum distance the target can be at. If the target is farther than this distance, the modification will solve as if it’s at this maximum distance. When set to 0, the modification will solve without distance constraints.

target_minimum_distance

float target_minimum_distance = 0.0

The minimum distance the target can be at. If the target is closer than this distance, the modification will solve as if it’s at this minimum distance. When set to 0, the modification will solve without distance constraints.

target_nodepath

EntityPath target_nodepath = EntityPath("")

The EntityPath to the node that is the target for the TwoBoneIK modification. This node is what the modification will use when bending the Bone2D nodes.

get_joint_one_bone2d_node

EntityPath get_joint_one_bone2d_node() const

Returns the Bone2D node that is being used as the first bone in the TwoBoneIK modification.

get_joint_one_bone_idx

int get_joint_one_bone_idx() const

Returns the index of the Bone2D node that is being used as the first bone in the TwoBoneIK modification.

get_joint_two_bone2d_node

EntityPath get_joint_two_bone2d_node() const

Returns the Bone2D node that is being used as the second bone in the TwoBoneIK modification.

get_joint_two_bone_idx

int get_joint_two_bone_idx() const

Returns the index of the Bone2D node that is being used as the second bone in the TwoBoneIK modification.

set_joint_one_bone2d_node

void set_joint_one_bone2d_node(bone2d_node: EntityPath)

Sets the Bone2D node that is being used as the first bone in the TwoBoneIK modification.

set_joint_one_bone_idx

void set_joint_one_bone_idx(bone_idx: int)

Sets the index of the Bone2D node that is being used as the first bone in the TwoBoneIK modification.

set_joint_two_bone2d_node

void set_joint_two_bone2d_node(bone2d_node: EntityPath)

Sets the Bone2D node that is being used as the second bone in the TwoBoneIK modification.

set_joint_two_bone_idx

void set_joint_two_bone_idx(bone_idx: int)

Sets the index of the Bone2D node that is being used as the second bone in the TwoBoneIK modification.