SkeletonModification2DTwoBoneIK
A modification that rotates two bones using the law of cosines to reach the target.
SkeletonModification2DTwoBoneIK.swift:20class SkeletonModification2DTwoBoneIK
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.
Superclasses
class SkeletonModification2D
Base class for resources that operate on
Bone2D
s in aSkeleton2D
.
Citizens in SwiftGodot
Conformances
protocol CustomStringConvertible
A type with a customized textual representation.
protocol Equatable
A type that can be compared for value equality.
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol Identifiable<ID>
A class of types whose instances hold the value of an entity with stable identity.
protocol VariantRepresentable
Types that conform to VariantRepresentable can be stored directly in
Variant
with no conversion. These include all of the Variant types from Godot (for exampleGString
,Rect
,Plane
), Godot objects (those that subclass SwiftGodot.Object) as well as the built-in Swift types UInt8, Int64 and Double.protocol VariantStorable
Types that conform to VariantStorable can be stored in a Variant and can be extracted back out of a Variant.
Type members
Instance members
var flipBendDirection: Bool
If
true
, the bones in the modification will blend outward as opposed to inwards when contracting. Iffalse
, the bones will bend inwards when contracting.var targetMaximumDistance: Double
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.var targetMinimumDistance: Double
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.var targetNodepath: NodePath
The NodePath to the node that is the target for the TwoBoneIK modification. This node is what the modification will use when bending the
Bone2D
nodes.func getJointOneBone2dNode(
) -> NodePath Returns the
Bone2D
node that is being used as the first bone in the TwoBoneIK modification.func getJointOneBoneIdx(
) -> Int32 Returns the index of the
Bone2D
node that is being used as the first bone in the TwoBoneIK modification.func getJointTwoBone2dNode(
) -> NodePath Returns the
Bone2D
node that is being used as the second bone in the TwoBoneIK modification.func getJointTwoBoneIdx(
) -> Int32 Returns the index of the
Bone2D
node that is being used as the second bone in the TwoBoneIK modification.func setJointOneBone2dNode(NodePath
) Sets the
Bone2D
node that is being used as the first bone in the TwoBoneIK modification.func setJointOneBoneIdx(Int32
) Sets the index of the
Bone2D
node that is being used as the first bone in the TwoBoneIK modification.func setJointTwoBone2dNode(NodePath
) Sets the
Bone2D
node that is being used as the second bone in the TwoBoneIK modification.func setJointTwoBoneIdx(Int32
) Sets the index of the
Bone2D
node that is being used as the second bone in the TwoBoneIK modification.