IKControl
IKControl instances generate procedural animation poses using Inverse Kinematics (IK). They allow you to make characters respond realistically to their environment.
For example, you can make a character place its hand on a door handle exactly, and the character will do so independently of its position. IKControls provide the advantage of needing to create much fewer animations for your game while giving your experience a more realistic and polished feel.
IKControls must be a child of a Humanoid or AnimationController with an Animator and have all of their required properties set properly, otherwise they don't have any effect. The required properties are Type, EndEffector, Target, ChainRoot. As soon as those are set, the IkControl modifies the pose of your character as you specify. The following code sample demonstrates how to set up your first IKControl and get started with creating more realistic animations for your game.
You can use IKControls to make a character:
- Rotate its head and torso to look at a point of interest in the world.
- Modify its feet positions to respond to dynamic terrain. Adjust its legs and feet to place them accordingly on terrain with rocks and slopes.
- Hold a gun and place its hands appropriately on the grip without needing to create animations for each gun in the game.
- Aim at a point in the world, so that the tip of the gun point exactly at what you want to shoot. Especially useful in third person shooters.
- Place its hands on the steering wheel of a car and follow it when it rotates.
- Much more!
IKControl will override the animation for all the parts between the ChainRoot and the EndEffector. You can enable/disable it using Enabled or change how much they have an effect over the underlying animation using the Weight. Be careful: if you do not set up your IKControls correctly, you might generate bad and unrealistic poses!
Code Samples
This sample shows the basic setup for an IKControl that moves a character's left arm to reach for a point in the world.
local character = script.Parent.Character
local humanoid = character.Humanoid
local root = character.HumanoidRootPart
-- Create a new attachment to use as the IKControl.Target
local target = Instance.new("Attachment")
target.CFrame = CFrame.new(-1, 0, -1)
target.Parent = root
local ikControl = Instance.new("IKControl")
ikControl.Type = Enum.IKControlType.Position
ikControl.EndEffector = character.LeftHand
ikControl.ChainRoot = character.LeftUpperArm
ikControl.Target = target
ikControl.Parent = humanoid
Summary
Properties
The last part that you are interested in moving your character. For example, the upper arm. Must be an ancestor of EndEffector and be a BasePart or a Bone in your character.
Toggles the control on and off. True by default.
The part that you are interested in moving to reach the Target. For example, the hand of your character. Must be a descendant of ChainRoot and be a BasePart or a Bone in your character.
An additional offset applied on top of the EndEffector in its local space to change where it moves.
An additional offset applied on top of the Target to change where the EndEffector moves.
An optional instance that determines which way the chain bends. You can use this to specify which way an elbow or knee bends.
Specifies the order in which controls are solved. Higher values have higher priority.
Specifies the average number of seconds that it takes for the EndEffector to smoothly reach the Target.
The object that the EndEffector reaches for or points at. It can be anything that has a position in the world, such as BasePart, Attachment, Bone, or Motor6D.
Specifies how the solver satisfies this control.
Specifies the weight of the IK control target. Should be in the [0, 1] range.