# Position Object always at the same distance of 2 other moving Objects?

I am making a procedural animation of a worm. I have already something working:

(the green dot is the position Target, purple and red are the Head and the Tail of the Worm)

I would like to add another dot in the center of the Worm to simulate the middle body waving up and down while Head and Tail are moving like this:

I thought that it was going to be easy using some kind of 2D joint, but I tried several and I was not able to find a good result.

I was also thinking that maybe I have to make some trigonometry to calculate the possible positions of Center:

Before I over-engineer the solution what would be your approach to solve this?

• It seems your looking for inverse kinematics. Here is a video that might help: youtube.com/watch?v=qqOAzn05fvk. This tutorial is for 3d but it can easily be changed for 2d. – Simonster Mar 30 at 17:55
• @Simonster This helped, I'll use it if my worm becomes more complex :) – fguillen Mar 30 at 18:39

My final approach has been using basic trigonometry:

I have a and b I was just needing to calculate c:

void MoveCenter()
{
float a = maxDistance / 2.0f;
float b = Vector3.Distance(head.position, tail.position) / 2.0f;
float c = Mathf.Sqrt(Mathf.Pow(a, 2.0f) - Mathf.Pow(b, 2.0f));