# Inverse Kinematics

**URL:** <https://forum.babylonjs.com/t/inverse-kinematics/46813>\
**Category:** Questions\
**Created:** [December 29, 2023, 8:32pm UTC](https://forum.babylonjs.com/t/inverse-kinematics/46813 "2023-12-29T20:32:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bico](https://avatars.discourse-cdn.com/v4/letter/b/67e7ee/32.png) [@bico](https://forum.babylonjs.com/u/bico)\
**Post date:** [December 29, 2023, 8:32pm UTC](https://forum.babylonjs.com/t/inverse-kinematics/46813/1 "2023-12-29T20:32:35Z")

</div>

I’m trying to set up inverse kinematics for a robot arm in Babylon.js. I’ve successfully set up a skeleton for a GLTF model, but I’m encountering issues with the mesh placement, and the code doesn’t seem to be solving the pose correctly for a moving target ball.

**Current Status:**

1. The skeleton is in place, and I’ve loaded a GLTF model for the robot arm.
2. However, the mesh isn’t positioned correctly. It seems to be displaced from where it should be, and I’m struggling to identify the root cause of this issue.
3. Additionally, I’m attempting to use inverse kinematics to control the robot arm’s pose in response to a moving target ball. Unfortunately, the current code doesn’t seem to be achieving the desired results.

Here is a complete playground with a skeleton created manually and configured to follow a ball

[IK | Babylon.js Playground (babylonjs.com)](https://playground.babylonjs.com/#BPVZNP)

I would greatly appreciate it if anyone could provide insights, suggestions, or perhaps even point out potential pitfalls in my approach. If you have successfully implemented inverse kinematics for robot arms in Babylon.js or have encountered similar issues, your guidance would be invaluable.

I found a few topics that relate to this issue and that helped me get to this point but i could not solve this issue:

- [Robot arm - inverse kinematics - Questions - Babylon.js (babylonjs.com)](https://forum.babylonjs.com/t/robot-arm-inverse-kinematics/15995/9)
- [IK (inverse kinematics) on GLB mesh - x is negated - Questions - Babylon.js (babylonjs.com)](https://forum.babylonjs.com/t/ik-inverse-kinematics-on-glb-mesh-x-is-negated/24571)

---

<div class="post-metadata">

**Author:** ![jumpjack2](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jumpjack2/32/36712_2.png) [@jumpjack2](https://forum.babylonjs.com/u/jumpjack2)\
**Post date:** [December 31, 2023, 7:03pm UTC](https://forum.babylonjs.com/t/inverse-kinematics/46813/2 "2023-12-31T19:03:35Z")

</div>

Check also my thread and PG, I decided to write from scratch my IK algorithm because I don’t understand how bones work in babylon…

> [@Weird behaviour while rotating intersection (manually calculating Inverse Kinematics)](https://forum.babylonjs.com/t/weird-behaviour-while-rotating-intersection-manually-calculating-inverse-kinematics/46489):
>
> This is my playground: [https://playground.babylonjs.com/#D25VJD#14](https://playground.babylonjs.com/#D25VJD#14) When I rotate the vertical wall around its vertical axis, intersection does not rotate: When I rotate around Z, thins get even weirder… [image] What’s going on here?!?

---

<div class="post-metadata">

**Author:** ![bico](https://avatars.discourse-cdn.com/v4/letter/b/67e7ee/32.png) [@bico](https://forum.babylonjs.com/u/bico)\
**Post date:** [January 2, 2024, 3:05pm UTC](https://forum.babylonjs.com/t/inverse-kinematics/46813/3 "2024-01-02T15:05:12Z")

</div>

Indeed, I’ve observed the recent modifications you made to the playground, and it’s an impressive demonstration. Regrettably, the integration with bones didn’t quite pan out. My objective here is to grasp the workings of Babylon in this context, enabling me to progress with the development of a new GLTF loader extension capable of utilizing Denavit–Hartenberg parameters. Unfortunately, I am still a newbie to this library and the migration from other engines has been slow.

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [January 2, 2024, 7:32pm UTC](https://forum.babylonjs.com/t/inverse-kinematics/46813/4 "2024-01-02T19:32:45Z")

</div>

Hello! Checking the console of the PG showed this:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/3/d/3d89f2e3bbfdc9029ce1914010c809d58a7db45a.png)

Additionally, I think the BoneIKController won’t be enough if you want to move all of the robot bones, as from the docs: [Bones and Skeletons | Babylon.js Documentation (babylonjs.com)](https://doc.babylonjs.com/features/featuresDeepDive/mesh/bonesSkeletons#boneikcontroller)

> The BoneIKController class is modeled after Blender’s IK Bone Constraint, but is currently limited to 2 bones.

---

<div class="post-metadata">

**Author:** ![bico](https://avatars.discourse-cdn.com/v4/letter/b/67e7ee/32.png) [@bico](https://forum.babylonjs.com/u/bico)\
**Post date:** [January 5, 2024, 10:03am UTC](https://forum.babylonjs.com/t/inverse-kinematics/46813/5 "2024-01-05T10:03:09Z")

</div>

Thank you Carol for pointing it out. Indeed in my experiments, I noticed it was working only for two bones but I thought it was my lack of understanding of the API
