- Home /

# Is that possible in unity?

https://www.youtube.com/watch?v=baCRowsIZ5Y

to set an additional gun mesh to the fps arms skeleton and link it with a constraint to use it as an ik target.

Sorry for my bad english.

**Answer** by hexagonius
·
Apr 19, 2019 at 02:29 PM

In Unity IK is supported only for character skeletons. If you need further IK capabilities like your setup, you can for example use "Final IK"

@hexagonius But there need to be another way ins$$anonymous$$d of buying final ik.

Sure, write your own I$$anonymous$$ solver. However if you have ever looked at the task of creating an I$$anonymous$$ solver you may have noticed that this problem does not have a general / unique / easy solution and for any kinematic chain that is longer than 2 it's quite difficult to pull off. Unity provides you with an I$$anonymous$$ solution but only for their well defined character bone hierarchy.

If you need some introduction in a simple iterative approximation, have a look at this article

@Bunny83 I found a simple Two Bone I$$anonymous$$ Code, but I dont know what i need to change to add a weapon as the I$$anonymous$$ target, (so i dont have to subtract offsets especially for the Aim Down Sights)

```
/// <summary>
/// Solve the bone chain.
/// </summary>
public static void Solve(Transform bone1, Transform bone2, Transform bone3, Vector3 targetPosition, Vector3 bendNormal, float weight) {
if (weight <= 0f) return;
// Direction of the limb in solver
targetPosition = Vector3.Lerp(bone3.position, targetPosition, weight);
Vector3 dir = targetPosition - bone1.position;
// Distance between the first and the last node solver positions
float length = dir.magnitude;
if (length == 0f) return;
float sqrMag1 = (bone2.position - bone1.position).sqrMagnitude;
float sqrMag2 = (bone3.position - bone2.position).sqrMagnitude;
// Get the general world space bending direction
Vector3 bendDir = Vector3.Cross(dir, bendNormal);
// Get the direction to the trigonometrically solved position of the second node
Vector3 toBendPoint = GetDirectionToBendPoint(dir, length, bendDir, sqrMag1, sqrMag2);
// Position the second node
Quaternion q1 = Quaternion.FromToRotation(bone2.position - bone1.position, toBendPoint);
if (weight < 1f) q1 = Quaternion.Lerp(Quaternion.identity, q1, weight);
bone1.rotation = q1 * bone1.rotation;
Quaternion q2 = Quaternion.FromToRotation(bone3.position - bone2.position, targetPosition - bone2.position);
if (weight < 1f) q2 = Quaternion.Lerp(Quaternion.identity, q2, weight);
bone2.rotation = q2 * bone2.rotation;
}
//Calculates the bend direction based on the law of cosines. NB! Magnitude of the returned vector does not equal to the length of the first bone!
private static Vector3 GetDirectionToBendPoint(Vector3 direction, float directionMag, Vector3 bendDirection, float sqrMag1, float sqrMag2) {
float x = ((directionMag * directionMag) + (sqrMag1 - sqrMag2)) / 2f / directionMag;
float y = (float)Math.Sqrt(Mathf.Clamp(sqrMag1 - x * x, 0, Mathf.Infinity));
if (direction == Vector3.zero) return Vector3.zero;
return Quaternion.LookRotation(direction, bendDirection) * new Vector3(0f, y, x);
}
```

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.